The server and its clients — WebSockets · NestJS

Make the desk feel live: lifecycle hooks for clients coming and going, the handshake's auth payload, the server behind the gateway, and the three ways to send an event: to one client, to everyone but the sender, to everyone.

What you will learn

Read the theory for The server and its clients

All WebSockets lessons

All NestJS courses

loading types…

What you'll learn

  • Run code when a client connects or disconnects with OnGatewayConnection and OnGatewayDisconnect, and when the server starts with OnGatewayInit
  • Read what a client sent in the handshake, socket.handshake.auth, before any message arrives
  • Get the socket.io Server with @WebSocketServer() and the sending client with @ConnectedSocket()
  • Choose between client.emit (that client), client.broadcast.emit (everyone else) and server.emit (everyone)