I have researched this topic online and have found nearly-similar questions to this - But, I need to know why in NestJS we have to use two packages to implement WebSocket communication.
The two packages are,
- @nestjs/websockets
- @nestjs/platform-socket.io
I understand that WebSocket is the protocol and Socket.IO is a library which has both server and client versions of it.
In the gateway file of NestJS when implementing a WebSocket connection, one has to write code similar to below.
import {
ConnectedSocket,
MessageBody,
OnGatewayConnection,
OnGatewayDisconnect,
SubscribeMessage,
WebSocketGateway,
WebSocketServer,
} from '@nestjs/websockets';
import { Server } from 'socket.io';
My questions,
What is the difference between
WebSocketServerandServerhere?Why do we import
Serverfromsocket.ioand not@nestjs/platform-socket.io?How do you describe the purpose of using each of these packages in a single sentence?