Esframewok-based client and Client Communication

Source: Internet
Author: User

This article describes the communication between the client and the server. This section describes the communication between the client and the client (through the server)

When the client is connected to the server, the server saves the connection information and manages the current user. For more information, see the series of articles.

User Management and TCP components adopt the Qiao mode, so they were slightly changed at the beginning.

1 Mtcpusermanager =   New Tcpusermanager ();
2 Mtcpusermanager. Start ();
3 Mtcpusermanager. tcpuserdisplayer = This . Tcpuserdisplayer1;
4
5 // Mtcpusermanager. someoneconnected + = new esframework. cbsimplestr (mtcpusermanager_someoneconnected );
6 // Mtcpusermanager. someonedisconnected + = new cbfortcpuserdisconn (mtcpusermanager_someonedisconnected );
7
8 Mtcpusermanagerbridge =   New Tcpusermanagerbridge ();
9 Mtcpusermanagerbridge. TCP = MTCP;
10 Mtcpusermanagerbridge. tcpusermanager = Mtcpusermanager;
11 Mtcpusermanagerbridge. contracthelper = Mcontracthelper;
12 Mtcpusermanagerbridge. basicrequestdealer = New Basicrequestdealer ();
13 Mtcpusermanagerbridge. initialize ();
14
15 This . Tcpuserdisplayer1.servicekeynamematcher =   New Servicekeynamematcher ();

The server adds the forwarding function.

1 If (Msg. header. destuserid ! = " 0000000000 " )
2 {
3 If (Mtcpusermanager. isuseronline (msg. header. destuserid ))
4 {
5 MTCP. senddata (mtcpusermanager. getuserconnectid (msg. header. destuserid), MSG );
6
7 Instantmessagecontract message =   New Instantmessagecontract ( New Contracthelper ());
8
9 Message. fillmyself (msg. Body, 0 );
10
11 Displaychatmsg ( String . Format ( " User {0} sent a message to user {1} " , MSG. header. userid, MSG. header. destuserid), message. messagetext );
12 }
13 }

 

Two basic components are created on the server. One is to process login and the other is to process and obtain friend information. They must be registered in the message dispatcher processing factory.

1 Esbrequestdealerfactory mesbrequestdealerfactory =   New Esbrequestdealerfactory ();
2 Mesbrequestdealerfactory. contracthelper = Mcontracthelper;
3 Mesbrequestdealerfactory. basicrequestdealer = New Basicrequestdealer ();
4 Mesbrequestdealerfactory. friendrelationdealer = New Friendrelationdealer ();

InCodeThere are many. If you are interested, you can directly view the code. it is worth mentioning that I used binary serialization when converting information to binary. this may not be good. It seems that other languages are not supported yet. NET platform serialization. some colleagues suggested that I use XML for serialization and then convert it to binary. Maybe this is a good way. I wish you could think for yourself.

In other words, the client changes a lot because it needs to communicate with other clients and manage friends.
The idea is:
1. First enter the user name and password to log on to the system.
After the user logs in successfully, I write some information that may be used to the public area. After receiving the information, I send it to the main UI.
2. Get and display friends.
Completed in the main UI load event and added friends to the friends list
3. Double-click a friend to chat with the friend.
4. When receiving a message sent by another user, check whether the dialog box for chatting with the user already exists. If not, display the message. Otherwise, create a new dialog box and display the received message.

There are many client code, but it is not difficult to understand, so I will not post it.
Previous client and server communication http://mediar.cnblogs.com/archive/2006/04/12/373143.html Based on esframewok

Code download http://files.cnblogs.com/mediar/im20060517.rar

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.