Client-server interaction comparison with native instances (comparing ajax, server-sent event, websocket/netsocket), websocketnetsocket

Source: Internet
Author: User

Client-server interaction comparison with native instances (comparing ajax, server-sent event, websocket/netsocket), websocketnetsocket

I learned the native instance of websocket yesterday and thought it is necessary to put several common client-serverRefreshingInteractive forms:

I. Ajax: the client determines when to send requests to the Server.

Such as refreshing comments and refreshing images.

The main purpose is to avoid refreshing the experience of new customers, but it is triggered by client operations to send requests to the Server.

There are many instances on the Internet. The native js or encapsulated jQurey are usually used, easy to understand, and easy to modify by yourself.

Ii. Server-sent event: regularly pushes content from the Server to the client

For example, it pushes the stock market status every second and text broadcasts of sports competitions every second.

The feature is that the client only needs to send a "come on, Please hit me" Request (automatically send when the page is opened, reducing user operations), and the Server will push it regularly. The disadvantage is traffic consumption.

Native instances can refer to w3school: server send event (http://www.w3school.com.cn/html5/html_5_serversentevents.asp)

3. Socket network communication: equal and free interaction between the two parties. You only need to receive it when I want to send it to you.

For example, chat scenario.

The feature is traffic saving. When the client wants to send the message, the server returns the message when it wants to return the message. The Listener socket on both sides is responsible.

I first learned about. Net Socket, which is a network communication based on the. net Framework. Generally, the instance uses the console program or WinForm.

WebSocket was newly introduced yesterday. The main difference between websocket and Net Socket is browser-oriented (WebSocket is used for web purposes). HTML5 support is required. Most browsers support websocket (ie10 or later, the latest FF and Chrome support, I heard that Safari once thought this technology was not secure and temporarily canceled the support), the most pity is the need. only the net4.5 and later versions are available, namely :. no System in net4.0. web. webSocket namespace (do not know whether another dll is used) -- however, WinServer2003 supports a maximum. net4.0 ......

In net4.0, I want to use the web form and socket: NetSocket as the console program. The ui can continue to send ws Protocol requests to the console program using web (html + js.

Native example reference: Leo (http://www.cnblogs.com/Leo_wl/archive/2013/04/12/3016063.html), the article mentions the above form, only one written mistake: GetSecKeyAccept () the appended string in the method is missing a "-" (before E914 ). It should be: byte [] encryptionString = SHA1.Create (). ComputeHash (Encoding. ASCII. GetBytes (key + "258eafa5-e914-4710995ca-c5ab0dc85b11 "));

I also wrote an instance demo that supports multiple web interfaces to communicate with the same server. For details, refer to the svn code of my "online ghost hunting" series:

Svn address: https: // 115.29.246.25/svn/Catghost/account: guest password: guest

12th version log:

1. Simulate the Server: Start the NetSocketDemo. Server project.

2. Simulate the client: catghost.websocketdemo target demo40.html page (can be opened more)

IV. Other keywords: SignalR (server push), round robin, Socket4Net (client encapsulation), SuperSocket (server encapsulation)

Other keywords are listed during the learning process for readers to expand their learning.

SignalR has not been learned yet. Polling is a conceptual understanding.

Socket4Net is encapsulation of Socket Client: http://websocket4net.codeplex.com

SuperSocket is the server-side encapsulation of Socket: http://superwebsocket.codeplex.com

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.