C # network communication framework networkcomms kernel Resolution 2 message processing process,

Source: Internet
Author: User

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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.