Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hit the WebSocket Endpoint?

I see that there is websocket endpoint which works out fins with Java tests. In logs I see

Connecting to: ws://127.0.0.1:8080/76f48a44-0af8-444c-ba97-3f1ed34afc91/tweets  

Just like any other REST API I would like to hit it via browser or curl, but when I do that I see

➜  tweetstream git:(master) ✗ curl ws://127.0.0.1:8080/b9b90525-4cd4-43de-b893-7ef107ad06c2/tweets  
curl: (1) Protocol ws not supported or disabled in libcurl  

and

➜  tweetstream git:(master) ✗ curl http://127.0.0.1:8080/b9b90525-4cd4-43de-b893-7ef107ad06c2/tweets
<html><head><title>Error</title></head><body>Not Found</body></html>%  

Is there a way to test websocket APIs with browser/curl?

like image 283
daydreamer Avatar asked Jul 11 '14 18:07

daydreamer


People also ask

How do I connect to a WebSocket endpoint?

In order to communicate using the WebSocket protocol, you need to create a WebSocket object; this will automatically attempt to open the connection to the server. The URL to which to connect; this should be the URL to which the WebSocket server will respond.

What is WebSocket endpoint?

The Web Socket Endpoint represents an object that can handle websocket conversations. Developers may extend this class in order to implement a programmatic websocket endpoint. The Endpoint class holds lifecycle methods that may be overridden to intercept websocket open, error and close events.

Can you ping a WebSocket?

Pings and Pongs: The Heartbeat of WebSockets At any point after the handshake, either the client or the server can choose to send a ping to the other party.

How do I access WebSocket server?

To open a websocket connection, we need to create new WebSocket using the special protocol ws in the url: let socket = new WebSocket("ws://javascript.info"); There's also encrypted wss:// protocol. It's like HTTPS for websockets.


2 Answers

This did the trick for me:

$ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: http://www.websocket.org" http://echo.websocket.org

from: http://www.thenerdary.net/post/24889968081/debugging-websockets-with-curl

like image 74
Damian Avatar answered Oct 03 '22 23:10

Damian


For completeness, I'd like to add my own CLI tool: websocat.

$ websocat wss://echo.websocket.org/
qwer
qwer
1234
1234

It does not do the "browser" part of the question, but should be a valid substitute for "curl" in this case.

like image 38
Vi. Avatar answered Oct 03 '22 23:10

Vi.