TCP/IP networking and Web socket

Heechul Yoon·2021년 4월 11일
0

LOG

목록 보기
59/62

Posting about web socket and real time networking

Before web socket

Before web socket, there is some way to network in http for real-time communication

Polling

  • Forwarding request in certain interval to server and get the data. We are not sure when the request and response arised in the real-time networking. But somehow it ends up remaining unwanted request and connection even though there is not any changes on the server side

Long polling

  • Forwarding request in certain interval to server but it wait for a few seconds to watch if there is any changes on the server. the waiting policy would be defined at the client side

Streaming

  • Create connection to a server and receive the data in a row. Thus, It is difficult for client to forward data to the server

But every method still stuck into ineffiency that its header is "overheaded" for real-time networking

How web socket works

  • As typical tcp connection, it starts with 3 way hand shaking as follow
  • porting on 80 or 443 to have connection with http get method,
  • using tcp socket in Operting System layered(?) by web socket protocol in which ensure frame and message as data forwarding unit

here we can check out its header

request

GET /chat
Host: javascript.info
Origin: https://javascript.info
Connection: Upgrade [1]
Upgrade: websocket [2]
Sec-WebSocket-Key: Iv8io/9s+lYFgZWcXczP8Q== [3]
Sec-WebSocket-Version: 13 [4]

now we pay attention to [1] and [2] which means "from now on, we are networking with websocket not with http". Literally, it upgrades http networking to websocket networking.
and with [3]WebSocket-key, client and server guarantee the origin of the response and request is reliable

response

Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: hsBlbuDTkk24srzEOTBUlZAlC2g= [1]

Once server recieve the request, it respond in http with [1]hashed result from the WebSocket-key from the previous request. if [1] doesn't match to the one in the client side, connection is not established

Summary

  • hand shaking over http protocol with http header
  • using http-80 or http-443 port so no any other port for web socket networking
  • using message as a unit of data broken down to frame
profile
Quit talking, Begin doing

0개의 댓글