[ ] Regression
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.
Websocket example doesn't work
I cloned master, installed example 02 dependencies and ran it. When I open ws.html, it says WebSocket connection to 'ws://localhost:81/' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
. Looking at the code, the port should be the default (3000), not 81. If I change it to localhost:3000 it still doesn't work but the error is now ws.html:4 WebSocket connection to 'ws://localhost:3000/' failed: Connection closed before receiving a handshake response
Nest version: 4.5.8 (master)
For Tooling issues:
- Node version: 6.11.1
- Platform: MacOS 10.12.6
Others:
Hi @andrewbents,
Fixed, let's try now.
@kamilmysliwiec
the client in index.html
kind of works, but not in ws.html
using plain websockets. You also forgot to change the port there, but If I set it to 3000
it still says Connection closed before receiving a handshake response
. Am I missing something?
To use ws.html
you need to set up a ws
adapter (it'll force Nest to use ws
instead of socket.io
). Full path /src/common/adapters/ws-adapter.ts
, tutorial https://docs.nestjs.com/websockets/adapter
@kamilmysliwiec still doesn't work. I use this adapter (app.useWebSocketAdapter(new WsAdapter());
) and the error is the same
I have the same problem.
@kamilmysliwiec Can you try the ws
example?
@fengcen You should also define port there - https://github.com/nestjs/nest/blob/master/examples/02-gateways/src/events/events.gateway.ts#L12
@WebSocketGateway({ port: 3001})
@vologab Can I use the same port for http and websocket ?
not working for me either
why is it closed?
Still does not work for me
As mentioned by @kamilmysliwiec this fixed it for me:
import { NestFactory } from '@nestjs/core'
import { WsAdapter } from '@nestjs/platform-ws' // <---
import { AppModule } from './app.module'
async function bootstrap() {
const app = await NestFactory.create(AppModule)
app.useWebSocketAdapter(new WsAdapter(app)) // <---
await app.listen(3000)
}
bootstrap()
I did not find it necessary to specify a unique port in the WebSocket Gateway definition
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Most helpful comment
As mentioned by @kamilmysliwiec this fixed it for me:
I did not find it necessary to specify a unique port in the WebSocket Gateway definition