Python Websockets连接拒绝了错误的校验和

2024-06-16 13:49:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我们有一个以太网RFID阅读器和一个测试程序,允许我们通过websockets与设备进行通信。测试程序可能是用C#编写的。但是,我试图编写的python脚本无法与设备通信。 代码如下所示:

import websocket
import thread
import time

def on_message(ws, message):
    print message

def on_error(ws, error):
    print error

def on_close(ws):
    print "### closed ###"

def test(ws):
    ws.send("<command><heartbeat/></command>")


if __name__ == "__main__":
    websocket.enableTrace(True)
    ws = websocket.WebSocketApp("ws://192.168.0.194:10001",
                              on_message = on_message,
                              on_error = on_error,
                              on_close = on_close)
    ws.on_open = test
    ws.run_forever()

当我使用网络嗅探器时,我可以清楚地看到python和读取器之间来回通信的多条线路,但是读取器正在关闭连接。你知道吗

我得到的唯一反馈是一个错误代码,描述如下:

Error when receiving the TCP channel
• Connection was aborted
• TCP/IP protocol error
• Permissible number of connections at one port was exceeded
• Check socket programming on the user side or find the fault with network analyzer
(Wireshark). 

通过网络嗅探器,我可以看到我所有的消息都有一个错误的校验和,比如:

Checksum: 0xcc83 (incorrect, should be 0xb8ad)

Tags: thetestimport网络messageclosewson