Breeze IM 3.3 Series three client-to-server communication modes

Source: Internet
Author: User

Communication Framework for Networkcomms 2.3.1

When using TCP communication, the client sends a message to the server, such as a message is the login message B message is the update password message server side how to distinguish A and B, and call the appropriate processor?

The NETWORKCOMMS communication framework uses this mechanism: the client assigns a "message type" to each message, and the server side finds the appropriate processor based on the "message type".

Take "login Message" as an example

Client code:

                //Save the user name and password in the contract classUserInfo UserInfo =NewUserInfo (); Userinfo.userid=TxtUserID.Texts.Trim (); Userinfo.password=TxtPassword.Texts.Trim (); //send the contract class to the server side and get the returned resultsUserlogincontract logincontract = newtcpconnection.sendreceiveobject<userlogincontract> ("Userlogin","Resuserlogin",8000, UserInfo); //If the login is successful                if(Logincontract.message = ="Success")                {
Do the next steps
}

UserInfo is a serializable class of contracts that can be used to pass information

"Userlogin" is the message type that we specify, the server side receives this type of message, calls the appropriate processor to process it, and, by convention, returns a message of the "Resuserlogin" message type.

The actual type of message sent is UserInfo

The actual type of message returned is Userlogincontract

Server-side code:

(1) The processor that declares the corresponding message type

Networkcomms.appendglobalincomingpackethandler<userinfo> ("userlogin", Incomingloginhandler);

(2) The specific processor

//Note The parameter type of the third parameter of the processor is consistent with the actual type of message sent by the client

Private voidIncomingloginhandler (packetheader header, Connection Connection, UserInfo UserInfo) {Try{userlogincontract rescontract;//Verifying logon information from the databaseRescontract =Dorcusers.login (Userinfo.userid, Userinfo.password);

The //Return message gives the client the actual data type of the message returned by the same connection as the data type that the client waits to get when it sends the message . SendObject ("Resuserlogin", rescontract);
} Catch(Exception ex) {logtools.logexception (ex,"Incomingloginhandler"); } }

www.networkcomms.cn Edit

Breeze IM 3.3 Series three client-to-server communication modes

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.