Handshake and Data Messages in WebSocket Protocol

Q

What are handshake and data messages used in WebSocket Protocol?

✍: FYIcenter.com

A

When a client and a server communicate with WebSocket protocol, they use the following handshake messages before and after their data transfer messages:

1. Client sends handshake request to server: "GET /chat HTTP/1.1". WebSocket borrows the HTTP request format for this message.

2. Server sends back this handshake response to client: "HTTP/1.1 101 Switching Protocols". WebSocket borrows the HTTP request format for this message.

3. Client starts to send data payload frames to server in a two-way communication style.

4. Server starts to send data payload frames to client in a two-way communication style.

5. Client sends "Close" frame to server.

6. Server sends "Close" frame to client.

The diagram below shows how client and server talk to each other in WebSocket protocol:
WebSocket Protocol - Handshake and Data Messages

 

Downloading and Reviewing WebSocket.jar

⇒⇒FAQ for WebSocket API

2018-01-27, 494👍, 0💬