如何调试Websocket?
我想监视 websocket 流量(例如查看客户端/服务器正在使用的协议版本)以进行调试。我该怎么做呢? Wireshark 对于这样的任务来说似乎太低级了。建议?
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? Wireshark seems too low level for such a task. Suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
Wireshark 听起来就像你真正想要的。握手后 WebSocket 几乎没有框架或结构(因此您需要低级),即使有,wireshark 也很快(或已经)能够解析它并向您显示结构。
就我个人而言,我经常使用 tcpdump 捕获数据,然后使用wireshark 解析数据。当您可能无法在想要捕获数据的设备(即无头服务器)上使用wireshark时,这尤其有用。例如:
或者,如果您可以控制 WebSockets 服务器(或代理),您可以随时打印出发送和接收的数据。请注意,由于 websocket 框架以 '\x00' 开头,因此希望避免打印它,因为在许多语言中 '\x00' 意味着字符串的结尾。
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:
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.
如果您正在寻找发送和接收的实际数据,最近的 Chrome Canary 和 Chromium 现在具有 WebSocket 消息帧检查功能。
您可以在此帖子中找到详细信息。
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.
我认为你应该使用Wireshark
步骤
tcp.dstport == your_websoket_port
I think you should use Wireshark
Steps
tcp.dstport == your_websoket_port
对于简单的事情来说,wireshark太复杂了,我只想检查是否可以建立连接。遵循 Chrome 插件“简单 Web-socket”(链接:https ://chrome.google.com/webstore/detail/simple-websocket-client/pfdhoblngboilpfeibdedpjgfnlcodoo?hl=en)”就像魅力一样。参见图片。
https://lh3.googleusercontent.com/bEHoKg3ijfjaE8- RWTONDBZolc3tP2mLbyWanolCfLmpTHUyYPMSD5I4hKBfi81D2hVpVH_BfQ=w640-h400- e365
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