如何调试 Websocket? [英] How to debug Websockets?

查看:40
本文介绍了如何调试 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?

推荐答案

Wireshark 听起来确实是您想要的.握手后,WebSockets 几乎没有框架或结构(所以你想要低级),即使有,wireshark 也很快(或已经)能够解析它并向你展示结构.

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.

就我个人而言,我经常用tcpdump捕获,然后再用wireshark解析数据.当您可能无法在要捕获数据的设备(即无头服务器)上进行wireshark 时,这尤其好.例如:

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

或者,如果您可以控制 WebSockets 服务器(或代理),您始终可以打印出发送和接收数据.请注意,由于 websocket 帧以 'x00' 开头,因此希望避免打印,因为在许多语言中,'x00' 表示字符串的结尾.

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.

这篇关于如何调试 Websocket?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆