Please enable JavaScript.
Coggle requires JavaScript to display documents.
1.6 WebSocket
and SignalR (decide when to use websockets …
1.6 WebSocket
and SignalR
.
two-way communication:
-
HTTP long polling
-
Workaround: reduce bandwidth- and server-usage
the server keeps request open until it has data to return or the connection times out (how to handle connection timeout?);
WebSockets
-
-
Upgrade HTTP to WebSocket handshake request:
GET /mychat HTTP/1.1
Host: server.example.com
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: hy6T&Ui8trDRGY5REWe4r5==
Sec-WebSocket-Protocol: chat
Sec-WebSocket-Version: 13
Origin: http://example.com
Upgrade HTTP to WebSocket handshake responce:
HTTP/1.1 101 Switching Protocols
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Accept: Ju6Tr4Ewed0p9Uyt6jNbgFD5t6=
Sec-WebSocket-Protocol: chat
-
Network
HTTP Request GET, DELETE: have header, has no body;
A lot of clients are unable to send DELETE request with a body;
HTTP Request POST, PUT: have both header and body;
-
.
- read/write string/binary data asyncronously;
jQuery
socket.AddEventListener("open"), function() { ... });
socket.AddEventListener("message"), function() { ... });
socket.AddEventListener("error"), function() { ... });
-
-
Conection loss: client side onclose and onerror event is thrown; server cannot reach out to the client when there is no connection.
Application state should be retained if there is conection loss in the process (application should be able recreate the connection and resend the message).
Client, server, network issue can break WebSocket connection.
The connection might have been broken after the data was received but before the sender was given the receipt; your code needs to allow for multiple receipts of information.
-
- implement web-socket features in Azure Web App
- decide when to use websockets
HTTP vs WebSocket
HTTP request (2800 bytes including cookie data, 490 bytes without cookie data): HTTP response (355 bytes because of headers):
Both HTTP and WebSockets have equivalent sized initial connection handshakes, but with a WebSocket connection the initial handshake is performed once.
WebSocket small messages only have 6 bytes of overhead (2 for the header and 4 for the mask value). The latency overhead is not so much from the size of the headers, but from the logic to parse/handle/store headers.
-
-
Network direct traffic by looking at HTTP headers, such as CONTENT-TYPE (websocket has a lightweight header), so traffic may be treated as malicious and newtwork send is cancelled.
-