中文 | English

RocketDriver Pro

Logo

RocketDriver Pro is a game framework for Unity engine


4. Network management extension module (NetManager)

Easy-to-use network link management module

4.1 Use of VirtualServer

4.1.1 Instantiate and add to NetManager management

var server = new VirtualServer("server", "none");
NetManager.Shared.Register(server, true);

image
Objects added to NetManager can be obtained by name.

4.1.2 Registering extensions

server.RegisterExtension(VirtualReqIds.Id0, 
  OnRequestHandler);

image

4.1.3 Protocol response

Response delegate declaration: VirtualServerDelegate.OnProtoRequestHandler image

4.1.4 Message Push

4.2 Use of VirtualClient

4.2.1 Instantiate and add to NetManager management.

var client = new VirtualClient("client", "none");
NetManager.Shared.Register(client, true);

image
Objects added to NetManager can be obtained by name.

4.2.2 Connecting to the server

var serverProxy = NetManager.Shared.
  GetServer<IVirtualServer>("server") as IVirtualServerProxy;
client.Connect(serverProxy);

image

4.2.3 Monitor request response, monitor message push

The monitoring function is built under the event mechanism:

client.AddEventListener(VirtualClientEvents.EventResponse,
  OnClientResponse);
client.AddEventListener(VirtualClientEvents.EventNotify,
  OnClientNotify);

image

4.2.4 Send message request

Use the Request function under the interface IVirtualClient to send a message request to the server.

NetManager.Shared.GetClient<IVirtualClient>("client")
  .Request(protoId, m_InputRequestData.text.Trim());

image

4.3 Example

JLGames/RocketDriver/Samples/NetManager
image