How to hit the WebSocket Endpoint?

后端 未结 6 1225
梦如初夏
梦如初夏 2021-02-05 22:52

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-3f1ed34af         


        
相关标签:
6条回答
  • 2021-02-05 23:04

    I have used this and found it to be quite simple

    http://www.websocket.org/echo.html

    0 讨论(0)
  • 2021-02-05 23:05

    I wrote a cURL like WebSocket client. You can send single data frame (text/binary) via this tool and then it closes the socket. Also you can add HTTP headers in the initial HTTP upgrade process.

    https://github.com/jussmen/WebSocket_cURL

    0 讨论(0)
  • 2021-02-05 23:12

    I had to use this command to make it work:

    $ curl -i -N -H "Connection: Upgrade" -H "Upgrade: websocket" -H "Host: echo.websocket.org" -H "Origin: http://www.websocket.org" -H "Sec-WebSocket-Version: 13" -H 'Sec-WebSocket-Key: +onQ3ZxjWlkNa0na6ydhNg==' http://www.websocket.org
    

    I am using Jetty, and if I didn't add the Sec-WebSocket-Version/Sec-WebSocket-Key doesn't work. Just for the record.

    0 讨论(0)
  • 2021-02-05 23:25

    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.

    0 讨论(0)
  • 2021-02-05 23:26

    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

    0 讨论(0)
  • 2021-02-05 23:30

    If you mean literally to test the implementation of websockets, I found Autobahn's test suite to be very useful: http://autobahn.ws/

    If you just want to noodle with a websocket I would recommend using the developer tools in a browser like chrome to make a connection and send/recv data:

    var ws = new WebSocket("ws://127.0.0.1:8080/76f48a44-0af8-444c-ba97-3f1ed34afc91/tweets");
    ws.onclose = function() { // thing to do on close
    };
    ws.onerror = function() { // thing to do on error
    };
    ws.onmessage = function() { // thing to do on message
    };
    ws.onopen = function() { // thing to do on open
    };
    ws.send("Hello World");
    
    0 讨论(0)
提交回复
热议问题