How to debug Websockets?

前端 未结 4 1216
情深已故
情深已故 2020-12-23 14:01

I want to monitor the websocket traffic (like to see what version of the protocol the client/server is using) for debugging purposes. How would I go about doing this? Wiresh

相关标签:
4条回答
  • 2020-12-23 14:36

    Wireshark sounds like what you want actually. There is very little framing or structure to WebSockets after the handshake (so you want low-level) and even if there was, wireshark would soon (or already) have the ability to parse it and show you the structure.

    Personally, I often capture with tcpdump and then parse the data later using wireshark. This is especially nice when you may not be able wireshark on the device where you want to capture the data (i.e. a headless server). For example:

    sudo tcpdump -w /tmp/capture_data -s 8192 port 8000
    

    Alternately, if you have control over the WebSockets server (or proxy) you could always print out the send and receive data. Note that since websocket frames start with '\x00' will want to avoid printing that since in many languages '\x00' means the end of the string.

    0 讨论(0)
  • 2020-12-23 14:42

    If you're looking for the actual data sent and received, the recent Chrome Canary and Chromium have now WebSocket message frame inspection feature. You find details in this thread.

    0 讨论(0)
  • 2020-12-23 14:42

    I think you should use Wireshark

    Steps

    • Open wireshark
    • Go to capture and follow bellow path: capture > interfaces > start capture in your appropriate device.
    • Write rules in filter tcp.dstport == your_websoket_port
    • Hit apply
    0 讨论(0)
  • 2020-12-23 14:44

    For simple thing, wireshark is too complex, i wanted to check only if the connection can be establish or not. Following Chrome plugin "Simple Web-socket (link : https://chrome.google.com/webstore/detail/simple-websocket-client/pfdhoblngboilpfeibdedpjgfnlcodoo?hl=en)" work like charm. See image.

    https://lh3.googleusercontent.com/bEHoKg3ijfjaE8-RWTONDBZolc3tP2mLbyWanolCfLmpTHUyYPMSD5I4hKBfi81D2hVpVH_BfQ=w640-h400-e365

    0 讨论(0)
提交回复
热议问题