Files
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)
Press Run tests to start the app. Its log appears here.Graded endpoints
handleConnection runs for the new client: it is welcomed with the number of visitors, and there is nobody else to tell
Bob gets his own welcome; Ada, already connected, hears his name from the handshake through client.broadcast.emit, and Bob does not hear himself arrive
The gateway remembered both visitors by socket id
Ada gets the new cat as her acknowledgement; Bob hears cats:added, and Ada does not hear it a second time
server.emit reaches every client, the adopter included, with the adopter's name from the handshake
A refused adoption is only acknowledged; nobody is told about something that did not happen
handleDisconnect runs; everyone still connected hears who left
The disconnect hook forgot Bob
A client whose handshake carries no name is still welcome, as A visitor
Run the tests first.