1.Introduction to WebSocket

Source: Internet
Author: User



Website English reference: Http://docs.oracle.com/javaee/7/tutorial/doc/websocket001.htm#BABDABHF
Chinese analysis:
Websocket application, server as a Websocket endpoint, the client connects to the server via the server's URL address. Once the server and client connections are established, it is a symmetric connection. When the server and client connect to open, they can send messages to each other at any time. A client typically connects only one server,server to support multiple client connections.
The WebSocket protocol is divided into two parts (handshake and data exchange). The client initiates the handshake request through the URL address, which is compatible with the current HTTP protocol. The server receives the request and understands it as an HTTP connection upgrade request.
Client-initiated connection handshake requests such as:
Get/path/to/websocket/endpoint Http/1.1host:localhostupgrade:websocketconnection:upgradesec-websocket-key: Xqbt3imnzjbyqrinxeflkg==origin:http://localhostsec-websocket-version:13

Response requests from the server such as:
http/1.1 101 Switching protocolsupgrade:websocketconnection:upgradesec-websocket-accept:k7djldlooiwig/ mopvwfb3y3fe8=
Server through a method that leveragesSec-websocket-key to producesec-websocket-accept. The client uses the same method toSec-websocket-key Generationsec-websocket-accept. If the received reply value is the same as the value that you calculate, then the connection is established. After the handshake succeeds, the server and client can send messages.
WebSocket supports text format and binary format, WebSocket method has Close,ping,pong.ping,pong method can contain data.
Websocket endpoints are differentiated by URIs, in the following two ways:
Ws://host:port/path?querywss://host:port/path?query
WS represents a non-encrypted connection, WSS represents an encrypted connection, and a port can be specified.                    Unencrypted communication defaults to port 80, the encrypted connection is 443 ports by default, path is the server endpoint, and query is optional. Mainstream browsers implement the WebSocket protocol and provide JavaScript interfaces (connecting to server endpoints, sending messages, callbacks)





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.