ET Framework-Server-NetOuterComponent Study Notes

NetOuterComponent

Please follow me on Weibo: @NormanLin_BadPixel Bad Pixel


namespace Model
{
    public class NetOuterComponent: NetworkComponent
    {
    }
}

Empty. With the previous lessons, this time I deliberately went to find out if there is an extension method. As expected.

public static class NetOuterComponentEx

We see that, like the client, it also subscribes to the Awake and Update events, and has an Awake method with a parameter, the parameter is the IP address.

public static void Awake(this NetOuterComponent self, IPEndPoint ipEndPoint)
{
    self.Awake(NetworkProtocol.TCP, ipEndPoint);
    self.MessagePacker = new ProtobufPacker();
    self.MessageDispatcher = new OuterMessageDispatcher();
}

From here, we know that its packaging tool for messages is ProtobufPacker , and the message dispatcher is OuterMessageDispatcher .

OuterMessageDispatcher

Let's first compare the processing that the server and client need to do after receiving the message.

After the client receives the message, it only needs to schedule with the hot update layer in its own mono layer. However, if the server receives the message from the client, in addition to the message scheduling in the service layer managed by itself, the client sends The message may also require us to access other servers. At this time, communication between our servers is required. This requires the use of the Actor knowledge we learned earlier. ( Actors we haven't learned yet.)

// gate session收到actor消息直接转发给actor自己去处理
if (message is IActorMessage)
{
    long actorId = session.GetComponent<SessionUserComponent>().User.ActorID;
    ActorProxy actorProxy = Game.Scene.GetComponent<ActorProxyComponent>().Get(actorId);
    actorProxy.Send((IMessage)message);
    return;
}

// gate session收到actor rpc消息,先向actor 发送rpc请求,再将请求结果返回客户端
if (message is IActorRequest aActorRequest)
{
    long actorId = session.GetComponent<SessionUserComponent>().User.ActorID;
    ActorProxy actorProxy = Game.Scene.GetComponent<ActorProxyComponent>().Get(actorId);
    IResponse response = await actorProxy.Call(aActorRequest);
    session.Reply(packetInfo.RpcId, response);
    return;
}

We found that there are really too many message types in the ET framework, and I want to write a note about the message types .

After the baptism of the above notes, everyone should understand why the news is handled in this way, haha. But we have to see how it locates ActorProxy .

We see that when the client sends a message to the server, the client can be identified through the Session , but when the server sends it to other servers, it has to be repackaged. At this time, the Session is already a conversation between the server and the server. Session is over, we need to save additional data that can identify the client.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325815550&siteId=291194637
Recommended