将数据发送到服务器时出现一些错误。我对 Python 套接字非常陌生,这是一个简单的脚本。这里是
Exception happened during processing of request from ('ip', 53863)
Traceback (most recent call last):
File "/usr/lib/python2.7/SocketServer.py", line 284, in _handle_request_noblock
self.process_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 310, in process_request
self.finish_request(request, client_address)
File "/usr/lib/python2.7/SocketServer.py", line 323, in finish_request
self.RequestHandlerClass(request, client_address, self)
File "/usr/lib/python2.7/SocketServer.py", line 638, in __init__
self.handle()
File "serv.pyz", line 9, in handle
print(self.client_address + ' : ' + self.data)
TypeError: can only concatenate tuple (not "str") to tuple
Serv.pyz(我知道,应该是 .py)
import SocketServer
class SEER(SocketServer.BaseRequestHandler):
def handle(self):
while 1:
self.data = self.request.recv(9000)
print(self.client_address + ' : ' + self.data)
server = SocketServer.TCPServer(('', 4857), SEER)
server.serve_forever()
另外,我如何添加一个 Client 类来存储诸如 Client.room_id 或 Client.joinRoom(1) 之类的东西?