Trung BìnhNode.js iconNode.js

Websocket với Socket.io trong Node.js dùng thế nào?

Socket.io wraps WebSocket với automatic reconnection, rooms, và namespace support.

js
// Server
const io = new Server(httpServer);
io.on('connection', socket => {
  socket.on('message', data => { io.emit('message', data); });
});
// Client
const socket = io('http://localhost:3000');
socket.emit('message', 'hello');

Rooms cho group chat, namespaces cho tách concerns.

Reconnection tự động.

Xem toàn bộ Node.js cùng filter theo level & chủ đề con.

Mở danh sách Node.js