Websocket example doesn't work
See original GitHub issueI’m submitting a…
[ ] 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.
Current behavior
Websocket example doesn’t work
Minimal reproduction of the problem with instructions
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
Environment
Nest version: 4.5.8 (master)
For Tooling issues:
- Node version: 6.11.1
- Platform: MacOS 10.12.6
Others:
Issue Analytics
- State:
- Created 6 years ago
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Websockets not working - Stack Overflow
Try this example: var url = "ws://echo.websocket.org"; if (!window.WebSocket) alert("WebSocket not supported by this browser"); var myWebSocket = { connect: ...
Read more >WebSocket - The Modern JavaScript Tutorial
A simple example. To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url:.
Read more >Troubleshooting connection issues | Socket.IO
You are trying to reach a plain WebSocket server; The server is not reachable; The client is not compatible with the version of...
Read more >Writing WebSocket client applications - Web APIs | MDN
WebSocket client applications use the WebSocket API to communicate with WebSocket servers using the WebSocket protocol.
Read more >How do I troubleshoot WebSocket issues in Agents (All ...
Ensure any load balancers or reverse proxies configured in your environment support WebSocket protocols. If they do not, you will see errors such...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
To use
ws.html
you need to set up aws
adapter (it’ll force Nest to usews
instead ofsocket.io
). Full path/src/common/adapters/ws-adapter.ts
, tutorial https://docs.nestjs.com/websockets/adapter