Python套接字服务器错误

Python套接字服务器错误,python,sockets,tcp,python-2.7,Python,Sockets,Tcp,Python 2.7,我在将数据发送到服务器时遇到一些错误。我对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_r

我在将数据发送到服务器时遇到一些错误。我对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)


另外,如何添加客户端类来存储Client.room\u id或Client.joinRoom(1)?

尝试将打印功能更改为:

    print(str(self.client_address) + ' : ' + str(self.data))

根据错误,其中一个变量是元组,因此应将其转换为字符串。

尝试将打印函数更改为:

    print(str(self.client_address) + ' : ' + str(self.data))

根据错误,其中一个变量是元组,因此应将其转换为字符串。

问题如回溯所示:

print(self.client_address + ' : ' + self.data)
self.client_地址是一个元组。您需要(在本例中)self.client_地址[0]
或者将其打印在单独的行上

问题如回溯所示:

print(self.client_address + ' : ' + self.data)
self.client_地址是一个元组。您需要(在本例中)self.client_地址[0]
或者将它们打印在单独的行中。

self.client\u address
是元组,您应该使用
self.client\u address[0]
来代替like。

self.client\u address
是元组,您应该使用
self.client\u address[0]
来代替like。

self.client\u address
是元组,而不是字符串!所以您需要打印它的str()

SEER
是您的客户机类,因此创建
self.room\u id
等来存储客户机状态和实现方法


TCP也是一种流协议,因此您需要在其上实现一个消息协议,以确保您拥有完整的消息。请参阅以获取示例。

self.client\u address
是一个元组,而不是字符串!所以您需要打印它的str()

SEER
是您的客户机类,因此创建
self.room\u id
等来存储客户机状态和实现方法

TCP也是一种流协议,因此您需要在其上实现一个消息协议,以确保您拥有完整的消息。有关示例,请参见