gpt4 book ai didi

Python 套接字服务器错误

转载 作者:可可西里 更新时间:2023-11-01 02:43:53 25 4
gpt4 key购买 nike

我在将数据发送到服务器时遇到一些错误。我是 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) 之类的东西?

最佳答案

self.client_address 是元组,你应该使用 self.client_address[0] 而不是 this .

关于Python 套接字服务器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12019189/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com