Esframework 4.0 Quick Start (09)-Chat System demo, add Silverlight client (with source code)

Source: Internet
Author: User

InEsframework 4.0 Quick Start-Getting Started demo, a simple IM system (with source code)This article introduces winform chat developed using the esframework rapid engine.ProgramIn this article, we will add a Silverlight client developed using esframework. SL based on the previous demo. In this way, not only can the Silverlight client communicate with each other, but also the Silverlight client can communicate with the winform client. If you do not know how to use esframework in Silverlight, You can first lookEsframework 4.0 Quick Start-use esframework in Silverlight.

The Silverlight client also implements and enhances the following functions:

(1) When a client user is online or offline, other online users are notified.

(2) When the client and server are disconnected from the network, automatic reconnection is performed. After the network is restored, the reconnection is successful.

(3) All online users (including winform clients) can chat in text.

(4) synchronous Message call. (Demonstrate three types of synchronous calls)

(5) re-login mode. When users with the same name log on, the previous users will be squeezed out.

 

I. Server

Directly used by the serverEsframework 4.0 Quick Start-Getting Started demo, a simple IM system (with source code)And added the server's function of synchronously calling the client-that is, the server submits a request to an online client and returns the client's reply information. We use "custom functions" in the "Tools" menu of the server UI. When you click this menu, a synchronous call request is sent to the first user in the online user list by default. The first online user is aa01. After you click "custom function", aa01 handles synchronous calls from the server.

The server synchronously calls the client using the icustomizeinfocontroller. queryclient () method.

///   <Summary>
/// Inquire about the online client and return the response information. A timeout exception is thrown if the target user is offline or has no response timeout.
///   </Summary>
///   <Param name = "userid"> Target User ID for receiving and processing server inquiries </Param>
///   <Param name = "informationtype"> Type of custom request information </Param>
///   <Param name = "info"> Request Information </Param>
///   <Returns> Response Information provided by the client </Returns>
Byte [] Queryclient ( String Userid, Int Informationtype, Byte [] Info );

 

Ii. Client

1. The mainpage class of the client implements esframework. SL. application. Basic.IbasicbusinesshandlerInterface to receive offline notifications, offline notifications, and heartbeat timeout notifications from other users.

2. The mainpage class of the client also implements esframework. SL. application. customizeinfo.IcustomizeinfobusinesshandlerTo process chat messages from other users, synchronous calls from the server, and P2P synchronous calls from other clients.

3. The mainpage class of the client is also scheduled and processed by esframework. SL. Rapid.IrapidpassiveengineThe tcppassiveengine attribute of tcppassiveengine is related to connection status changes, such as connection disconnection, reconnection start, and reconnection success/failure.

After the client starts to log on, the main page mainpage is displayed as follows:


When another user logs in, it is displayed in the "online user list". Click "Select User ID" to chat with the user. On the right side of the UI is the chat history with the selected user. below is the text box for sending messages. Select the target user from the online user list, enter the text in the chat input box, and click "send. Program through esframework. SL. application. customizeinfo.IcustomizeinfooutterTo send messages to friends.

Void Send ( String Targetuserid, Int Informationtype, Byte [] Info );

When a friend is offline, the name of the friend disappears from the friend list. If you are chatting with the friend, the history on the right is cleared and the send button is no longer available.

If we log on to another aa01 (Demo re-login), the program will first call back esframework. SL. application. Basic.IbasicbusinesshandlerOnbeingpushedout (), and then trigger the connectioninterrupted event of tcppassiveengine to notify the current user.

3. synchronous call

This demo demonstrates three types of synchronous calls: Synchronous calls between the client and the client, synchronous calls by the client to the server, and synchronous calls by the server.

1. synchronous client call server: This is demonstrated in the previous demo. The same mode is used in the sliverlight client.

 

2. synchronous client call by the server: This is introduced in the first part, and the client is implemented throughIcustomizeinfobusinesshandlerThe handlequeryfromserver method of the interface is used to process synchronous calls from the server:

///   <Summary>
/// Process the query information from the server and provide the response information. (Processing the request sent by icustomizeinfocontroller. queryclient)
///   </Summary>
///   <Param name = "informationtype"> Custom information type </Param>
///   <Param name = "info"> Binary information </Param>
///   <Returns> Response Information </Returns>
Byte [] Handlequeryfromserver ( Int Informationtype, Byte [] Info );

 

3. synchronous client call: The call is sent by the commitp2prequest method of the icustomizeinfooutter interface,

///   <Summary>
/// Submit the request information to the online target user and return the response information. A timeout exception is thrown if the target user is offline or has no response timeout.
///   </Summary>
///   <Param name = "targetuserid"> Target User ID for receiving and processing request messages </Param>
///   <Param name = "requestinfotype"> Type of custom request information </Param>
///   <Param name = "requestinfo"> Request Information </Param>
///   <Returns> Response Information </Returns>
Byte [] Commitp2prequest ( String Targetuserid, Int Requestinfotype, Byte [] Requestinfo );

After the target client receives a synchronous call request from another userIcustomizeinfobusinesshandlerThe handlep2prequest method of the interface to process this request:

Byte [] Handlep2prequest ( String Sourceuserid, Int Requestinfotype, Byte [] Requestinfo );

 

4. Two types of clients share the same server

The winform client and Silverlight client developed based on the esframework rapid engine can share the same server. In the future, esframework may support C ++/flash/Java-based clients. Is the communication between the Silverlight client and the winform client user after the demo is started.

 

 

V. Download demo source code

Download the demo source code of this Article. Note: When running a client program based on Silverlight, the server should first start with the "Silverlight policy server ".Esframework 4.0 OverviewDownload policy server at the end of this article.

 

Esframework 4.0 Overview

Esframework 4.0 Quick StartArticle

All articles in esframework 4.0 advanced edition Series

 

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.