Advanced CommunicationLesson 72Free preview
Socket.IO
This lesson is part of Node.js · All levels
Summary
This lesson discusses Socket.IO, a WebSocket-based real-time two-way communication library for Node.js applications. You'll create a server with http.createServer and then install Socket.IO, and use the emitter and on to exchange events between the server and the client. Deals with fallback transport and disconnect handling.
Key points
- Install socket.io (server) and socket.io-client (customer) through npm.
- The server: new Server(httpServer) and then io.on('connection', socket =>...).
- Socket.emit sends events to one client; io.emit sends to all connected clients.
- Events can carry a JSON payload in the form of objects or arrays.
- The socket.join(room) and io.to(room) support multiplayer chat rooms.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.