Before the company's real-time chat with the regular round, has always felt very unscientific, the recent backstage said configuration good socket server, I am happy to prepare with asyncsocket, but told me to use WebSocket, based on HTML5, A new bidirectional communication protocol (--websocket) is proposed in HTML5, this paper attempts to use this technology to realize the above real-time chat function.Af
Serverendpoint respectively define the interface method of client and server end endpoints;4.Decoder and encoder are decoding and coding interface method definitions respectively;5.Session is the WebSocket session interface method definition associated with endpoint.There are other interfaces as well, here as a preliminary understanding of the Java WebSocket API listing only the most necessary ones.TOMCAT8
pipes unless one of them cuts the pipe, and if the server does not support, the client requests the link to fail, returning an error message;
HTTP and WebSocket response header comparison:
The difference between WebSocket and Ajax polling, long poll
The first is Ajax polling, the principle of Ajax polling is very simple, let the browser send a request eve
analysis Node.js" time, saw the WebSocket that section, saw the websocket of the data frame definition, want to use NODEJS implementation. After some toss to achieve.
The client's code is not said, WebSocket API is very simple, through the OnMessage, OnOpen, OnClose, and send method can be implemented.The
= null;if (Preg_match ("/sec-websocket-key: (. *) \r\n/", $req, $match)) {$key = $match [1];}return $key;}
Here is relatively simple, direct regular matching, websocket information header must contain Sec-websocket-key, so we match up also relatively fast ~
3. Encrypt Sec-websocke
are used, unless one party manually disconnects the pipe. If the server does not support the pipe, the client request link fails and an error message is returned;
Http and websocket Response Headers:
Differences between websocket and ajax Round Robin and long poll
The first is ajax round-robin. The principle of ajax round-robin is very simple. Let the browser
server code, when the client connects, we can see:2. Extracting Sec-websocket-key InformationCopy CodeThe code is as follows:function GetKey ($req) {$key = null;if (Preg_match ("/sec-websocket-key: (. *) \r\n/", $req, $match)) {$key = $match [1];}return $key;}Here is relatively simple, direct regular matching, websocket
SHA-1 encryption, and then perform BASE-64 encoding. Use the result as the value of the "Sec-WebSocket-Accept" header and return it to the client (from Wikipedia ). After websocket API handshake, the browser establishes a connection with the server, and the two can communicate with each other. Websocket APIs are really simpl
a · What is WebSocketThe WebSocket protocol can communicate more than once after a successful handshake from the HTTP protocol until the connection is closed. However, the handshake in WebSocket is compatible with the handshake in HTTP, which uses the Upgrade protocol header in HTTP to upgrade the connection from HTTP to WebSocket. This makes it easier for the
programming implementation, but also increases the server-side load, restricting the scalability of the application system.HTML5 WebSocket designed to replace polling and Comet technology, so that the client browser has a desktop system like the C/s architecture of real-time communication capabilities. The browser sends a request to the server to establish a WebSocket connection through JavaScript, and aft
This is a creation in
Article, where the information may have evolved or changed.
In the Server.go file in Google's officially maintained Code.google.com\p\go.net\websocket package, there was a description:
//handler" is a simple interface to a WebSocket browser client. //It checks if Origin header is a valid URL by default. //You might want to verify
This article synchronizes to http://www.waylau.com/go-websocket-chat/ This sample application shows how to create a simple Web chat application using WebSocket, Golang, and JQuery. The source code for this example is https://github.com/waylau/goChat. Running The example run exampleThis example requires a Golang development environment. This page describes how to
WebSocket connection (ws://) server, if there is a transparent proxy server in the middle, the connection may fail, or send the message will fail, and the encrypted websocket connection in the presence of transparent proxy server, the probability of success is relatively large; For more information about proxies see: http://www.infoq.com/cn/articles/Web-Sockets-Proxy-Servers7),
This is a creation in
Article, where the information may have evolved or changed.
This article synchronizes to http://www.waylau.com/go-websocket-chat/
This sample application shows how to create a simple Web chat application using WebSocket, Golang, and JQuery. The source code for this example is https://github.com/waylau/goChat.
Running The example run examp
-------------------------------------------
Continue to say that WebSocket can see some things from w3c, such
Content sent from the client to the server:
1. GET/chat HTTP/1.12. Host: server.example.com3. Upgrade: websocket4. Connection: Upgrade5. Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ =6. Origin: http://example.com7. Sec-WebSocket-Protocol: chat, superchat8.
Transferred from: http://www.cnblogs.com/hsxixi/archive/2011/12/24/2300641.htmlFrom this time on, let's set up a simple chat room. Because the HTTP protocol is stateless, building a chat room like this has never felt gegedada is not so logical. If you do not use the flash, applets and other browser plug-ins, we need to periodically poll the server to get everyone's chat information. This creates a certain amount of latency and a lot of network traffic
as:Ws://example.com/chatwss://example.com/chatBy default, the WS protocol for Websocket uses port 80, and the WSS protocol uses 443 ports by default when running over TLS. In fact, WSS is the WS SSL-based secure transmission, and HTTPS as the same kind of truth.If your site is HTTPS protocol, then you can not use, the ws:// browser will block off the connection, and HTTPS does not allow the same HTTP request, such as:650) this.width=650; "Src=" http:
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.