C # network communication framework networkcomms kernel Resolution 2 message processing process,
Networkcomms.net from the UK official website of the network communication framework www.networkcomms.net Chinese website www.networkcomms.cn
The sender sends a message to the receiver for processing.
For example, the client transmits a user information (user ID and user password) to the server, and the server stores the user information in the database.
Sender
1. Contract (User Information)
[ProtoContract] public class UserInfo { [ProtoMember(1)] public string UserID; [ProtoMember(2)] public string Password; public UserInfo() { } public UserInfo(string userID, string password) { this.UserID = userID; this.Password = password; } }
2. assign values to the Contract class
UserInfo info = new UserInfo ("My User ID", "123456 ");
3. client-side Transmission
connection.SendObject("SendUserInfo", info);
So far, we have sent a contract class of the actual type UserInfo to the server. The message type sent this time is SendUserInfo.
Acceptor
1. register the Message Type
(When the receiving end receives a message whose message type is SendUserInfo, it calls the HandleUserInfo method for processing.
NetworkComms.AppendGlobalIncomingPacketHandler<UserInfo>("SendUserInfo", HandleUserInfo);
2. The parameter formats of related processing methods are unified. The third parameter type is set to the actual type sent by the client.
The networkcomms communication framework resolves the received binary data to the actual type.
Private void HandleUserInfo (PacketHeader header, Connection connection, UserInfo userInfo) {// process the received contract class userInfo string userID = userInfo. userID; string passWord = userInfo. password; // Save the obtained data to the database}
Process ended