python - OSError: [WinError 10056] 在已连接的套接字上发出了连接请求
问题描述
我想让连接自动化。运行代码时遇到以下问题。尝试添加断开连接,但没有奏效。系统正在连接并正在传输数据。一旦连接丢失并且系统尝试重新连接时,我就会面临这个问题。
import socket,time
client=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
ip = '192.168.xx.x'
port = 4xxx
address = (ip,port)
def connect():
try:
while 1:
print("connecting")
try:
client.connect(address)
print("connected")
except TimeoutError:
print("wait for few mins")
time.sleep(20)
connect()
break
except ConnectionAbortedError:
print("connection aborted wait for few sec")
time.sleep(10)
connect()
connect()
try:
while 1:
datasent = client.send(b'\x01\x04')
if datasent:
print("sent")
data= client.recv(1024)
print(data)
time.sleep(5)
if not datasent:
connect()
except ConnectionResetError:
client.shutdown(socket.SHUT_RDWR)
client.close()
print("wait for 10 sec")
time.sleep(10)
connect()
>Error: Traceback (most recent call last):
File "C:\Users\User\eclipse-workspace\Data\ckeck\client.py", line 28, in <module>
datasent = client.send(b'\x01\x04\')
ConnectionResetError: [WinError 10054] An existing connection was forcibly closed by the remote host
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\User\eclipse-workspace\Data\ckeck\client.py", line 41, in <module>
connect()
File "C:\Users\User\eclipse-workspace\Data\ckeck\client.py", line 13, in connect
client.connect(address)
OSError: [WinError 10038] An operation was attempted on something that is not a socket
解决方案
推荐阅读
- c# - 为什么用预制件替换游戏对象时,预制件位置有点靠后,而不是完全在游戏对象位置上?
- c++ - 在 C++ 中声明向量时出现意外错误
- python - Python + Pygame;screen.fill() 崩溃窗口
- rest - 颤振http帖子“类型'int'不是类型转换中'String'类型的子类型”
- linux - 为什么 echo $'\n' 打印 2 个新行?
- redux - 获取 'bundle.js:1 Uncaught SyntaxError: Unexpected token '<' in react/redux app
- java - 如何从计数器应用程序中的 sharedpreferences 编号中进行计数
- javascript - 如何在 Node.js Web 服务器中使用超链接?
- c - sprintf 和 uint64_t (avr-libc 2.0.0) 的问题
- python - 将带有值的按钮重定向到其他 django 模板/视图