WS, WSS, Websocket → Interaction or two-way communication based on HTML5 and HTTP(S)
WebSocket (웹소켓)
WebSocket is based on HTTP(S) and was introduced in HTML5
It is a technology that realized real-time interaction (two-way communication) which was difficult between HTTP server and client,
WebSocket connects to the server using port 80 and port 443 for HTTP (ws://) and HTTPS (wss://), respectively.
.
1. Socket.IO
Socket.IO provides the most general-purpose module or library,
It required implementing event-based, real-time, and bidirectional Websocket communication in the server and client.
♦ Server Socket.IO
io.on(‘connection’, callback(socket)) | The socket is connected and a new client connects. |
socket.on(event-name, callback(data)) |
Receive event, Process message/event through callback function for the event from the client socket. |
socket.emit(event-name, data) |
Sending an event Sending data to a specific client with some event. |
socket.broadcast.emit(event-name, data) |
Send event Send data to all clients with some event. |
io.of(name-space) | Set up sending and receiving messages in the same namespace |
♦ Client Socket.IO
io.connect( ) | Create a socket. |
socket.on(event-name, callback(data)) |
Receive event Process message/event through callback function for certain event. |
socket.emit(event-name, data) |
Send event, Send data to server with some event. |
io(name-space) | Set up sending and receiving messages in the same namespace |
2. WebSocket Application
The feature of WebSocket, which enables two-way communication in real time without disconnecting the connection,
is mainly used in places where real-time data exchange is required,
such as online games or stock trading systems.