发送消息时Python Websocket服务器错误

时间:2015-06-08 13:25:51

标签: python websocket server

任何人都可以出于某种原因帮助我使用我的python WebSockets服务器每当我尝试发送JSON数据时会出现很多错误,这里是我的代码的链接:

http://textuploader.com/v5kn

自上次更新以来,我的客户端没有更改,并且在连接到服务器后没有发送任何内容,所以应该没问题。

继承错误:

connection established ('127.0.0.1', 51777)
Handshaking...
----------------------------------------
Exception happened during processing of request from ('127.0.0.1', 51429)
Traceback (most recent call last):
  File "C:\Python27\lib\SocketServer.py", line 599, in process_request_thread
    self.finish_request(request, client_address)
  File "C:\Python27\lib\SocketServer.py", line 334, in finish_request
    self.RequestHandlerClass(request, client_address, self)
  File "C:\Python27\lib\SocketServer.py", line 655, in __init__
    self.handle()
  File "C:/Users/Heslop/Desktop/Projects/SnakeServer/server.py", line 64, in handle
    self.read_next_message()
  File "C:/Users/Heslop/Desktop/Projects/SnakeServer/server.py", line 68, in read_next_message
    length = ord(self.rfile.read(2)[1]) & 127
IndexError: string index out of range

1 个答案:

答案 0 :(得分:0)

实际上,您可以为您尝试使用ServerSide-ClientSide msg(frame)编码和解码的第三个库,这样您就可以专注于构建应用程序。

这是我的小包装:https://github.com/HelloLyfing/py-websocket-helper

因为我是唯一一个使用过这个包装的人,所以如果你有任何问题,请告诉我。