我正在这段代码上

from socket import *
HOST = 'localhost'
PORT = 21567
BUFSIZ = 1024
ADDR = (HOST, PORT)
serversock = socket(AF_INET, SOCK_STREAM)
serversock.bind(ADDR)
serversock.listen(2)

while 1:
    print ("waiting on connection")
    clientsock, addr = serversock.accept()
    print ('connected from:', addr)
    while 1:
        data = clientsock.recv(1024).decode()
        if not data: break
        clientsock.send(data.encode())
        clientsock.close()

serversock.close()

我收到此错误:
OSError: [WinError 10038] an operation was attempted on something that is not a socket

最佳答案

您仅在读取部分数据后关闭了clientock。

clientsock.close()

缩进级别错误。将其向左移动一步。

关于python socket编程OSError : [WinError 10038] an operation was attempted on something that is not a socket,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15210178/

10-16 16:21