我们有一个以太网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)