WebSocket
- Implemented by
WebSocket class
- Bidirectional: both client and server exchange the messages
- Data: Binary and Text Data
- Protocol: WebSocket:
ws://
wss:// (with TLS) - Similar to https://
- First the handshake is done by client request and server response
- Then connection is upgraded from
http:// to ws:// protocol
- WebSocket class:
- Methods:
socket.send(data)
socket.close([code], [reason])
- Events:
Server Sent Events (SSE)
- Implemented by
EventSource class
- Unidirectional: Server sends the data
- Data: Only Text Data
- Protocol: HTTP
- Simple to implement compared to WebSockets
- EventSource class:
- Properties:
readyState:
EventSource.CONNECTING (0)
EventSource.OPEN (1)
EventSource.CLOSED (2)
lastEventId
- Methods:
- Events:
- Spring boot SSE implementation: https://www.baeldung.com/spring-server-sent-events
Long Polling