Python 固定其他客户端上的偏移量';重新进入视野时的字符(PyGame和sockets)

Python 固定其他客户端上的偏移量';重新进入视野时的字符(PyGame和sockets),python,sockets,pygame,logic,Python,Sockets,Pygame,Logic,我希望在这里发布一个问题没有坏处。它真的让我发疯 您的网络代码无法处理客户端断开连接。检测这种情况的一种简单方法是,套接字.recv()返回一个空的数据列表。目前它进入了一个快速无限循环 对esuhanigop.pythreaded\u client()函数的一个小补丁就足以解决此问题: def threaded_client(connection,addr): while True: data = connection.recv(2048) if ( l

我希望在这里发布一个问题没有坏处。它真的让我发疯


您的网络代码无法处理客户端断开连接。检测这种情况的一种简单方法是,套接字
.recv()
返回一个空的数据列表。目前它进入了一个快速无限循环

esuhanigop.py
threaded\u client()
函数的一个小补丁就足以解决此问题:

def threaded_client(connection,addr):
    while True:
        data = connection.recv(2048)
        if ( len( data ) == 0 ):                     # Client has disconnected
            break                                    # Stop communications
        set_dat(addr,str(data,encoding='UTF-8'))
        dat = get_dat()
        if dat:
            connection.sendall(str.encode(dat,encoding='UTF-8'))
    connection.close()

使用此修补程序,我可以多次连接和断开与服务器的连接,而不会看到任何python错误。

您的问题需要包括相关的代码部分,并清楚地描述问题-正在发生的情况以及预期会发生的情况。请看