会引发ConnectionResetError的代码
Posted ravener
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了会引发ConnectionResetError的代码相关的知识,希望对你有一定的参考价值。
服务端selectserver.py
from socket import *
from select import select
s = socket(AF_INET, SOCK_STREAM)
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
s.bind((‘127.0.0.1‘, 10002))
s.listen()
rlist = [s]
wlist = []
xlist = []
while True:
print(‘Waiting for connect...‘)
rs, ws, xs = select(rlist, wlist, xlist)
for fb in rs:
if fb is s:
conn,addr = s.accept()
print(‘connect with %s%s‘%addr)
conn.send(‘connection stable‘.encode())
rlist.append(conn)
else:
data = fb.recv(4096)
if not data:
print(‘%s%s断开连接‘%fb.getsockname())
rlist.remove(fb)
fb.close()
else:
print(‘从%s%s收到:‘%fb.getsockname(), data.decode())
fb.send(‘recv checked‘.encode())
客户端selectclient.py
from socket import *
s = socket(AF_INET, SOCK_STREAM)
s.connect((‘127.0.0.1‘, 10002))
while True:
#data = s.recv(4096)
#print(‘server:‘, data.decode())
si = input(‘client:‘)
if not si:
s.close()
break
data = si.encode()
n = s.send(data)
print(‘发送%d字节‘%n)
data = s.recv(4096)
print(‘server:‘, data.decode())
在客户端断开时
Traceback (most recent call last):
File "selectserver.py", line 21, in
以上是关于会引发ConnectionResetError的代码的主要内容,如果未能解决你的问题,请参考以下文章
Websockets 错误: ConnectionResetError: [Errno 104] Connection reset by peer
Pika 连接丢失错误:pika.exceptions.StreamLostError:流连接丢失:ConnectionResetError(104,'对等连接重置')
ConnectionResetError: [WinError 10054] 现有连接被 ChromeDriver Chrome Selenium Django 的远程主机错误强行关闭
Could not install packages due to an OSError: ("Connection broken: ConnectionResetError(10054,
解决 ('Connection aborted.', ConnectionResetError(54, 'Connection reset by peer')) 问题(
Django错误: ConnectionResetError: [Errno 54] Connection reset by peer