4

We want to be able to test the Socket IO connection on our Node (Express) backend without using the SocketsIOClient (which does work!), using cURL (or another command line tool).

I found the following:

curl --verbose -i -N -H "Upgrade: websocket" -H "Connection: Upgrade" http://<API_URL>:<PORT> 

However, this does not work. Even when using http://localhost:3000 and running locally, it did not work. This is the response:

* Trying ::1... * TCP_NODELAY set * Connected to localhost (::1) port 3000 (#0) > GET / HTTP/1.1 > Host: localhost:3000 > User-Agent: curl/7.64.1 > Accept: */* > Upgrade: websocket > Connection: Upgrade > * Empty reply from server * Connection #0 to host localhost left intact curl: (52) Empty reply from server * Closing connection 0 
2
  • Why are you trying to test Socket.io without using a Socket.io client? Certainly an HTTP client doesn't make much sense for testing it (unless you are doing development of the socket.io server library itself and want to test the HTTP specific bits of it). Commented Feb 13, 2020 at 16:22
  • 2
    It makes sense when you're working on an architecture with multiple layers. We route through about 6 different systems. And one of those is not allowing the socket to pass through. If we had a command line cURL, we could easily test at each phase. Also allows us to make architecture changes and test that sockets will still work following the changes. Does that make sense? Commented Feb 14, 2020 at 11:22

1 Answer 1

8
npx wscat -c ws://localhost:3000/socket.io/\?transport=websocket 

This worked for me to establish WebSockets connection

If the last line of output is < 40, "event-name" event with "new message" message can be emitted with the following command

> 42["event-name","new message"] 
Sign up to request clarification or add additional context in comments.

3 Comments

Wow man this is really helpful, i didnt know you have to add this path when testing with wscat, before i got error socket hang up, now it works. i love you
Didn't know about this package. It's was helpful enough in telling me if I were connecting to websocket server successfully, however I couldn't send/receive events because of this error error: Invalid WebSocket frame: RSV1 must be clear
same error here: $ npx wscat -c ws://localhost:3006/socket.io/\?transport=websocket Connected (press CTRL+C to quit) error: Invalid WebSocket frame: RSV1 must be clear

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.