python 套接字编程 OSError: [WinError 10038] 尝试对不是套接字的东西进行操作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15210178/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-18 19:31:26 来源:igfitidea点击:
python socket programming OSError: [WinError 10038] an operation was attempted on something that is not a socket
提问by user2133251
I am working on this code
我正在处理此代码
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()
I get this error:
我收到此错误:
OSError: [WinError 10038] an operation was attempted on something that is not a socket
回答by Rob?
You are closing the clientsock after reading only part of the data.
您在仅读取部分数据后关闭了客户端。
clientsock.close()
is at the wrong level of indentation. Move it to the left by one step.
处于错误的缩进级别。将其向左移动一步。

