我正在創建一個程式,在通過套接字接收到時間、ID 和密碼后激活計時器。當我輸入“分鐘”值時,我有winError 10053。我不明白,為什么可以發送名稱和小時,而不是分鐘?
這是客戶代碼
declStart = input("if you want to login, enter "login" ") # GUI ??? ???? ??
if declStart=="login":
while True:
cname = str(input('enter name :'))
if ' ' in cname:
print('Spaces are not allowed.')
continue
client_sock.send(cname.encode())
is_possible_name = client_sock.recv(1024).decode()
if is_possible_name == 'yes':
client_sock.send('!enter'.encode())
goaltime_hour = int(input('goaltime(hour): '))
client_sock.send((str(goaltime_hour)).encode())
goaltime_min = int(input('goaltime(min): '))
client_sock.send((str(goaltime_min)).encode())
goaltime_sec = int(input('goaltime(sec): '))
client_sock.send((str(goaltime_sec)).encode())
elif is_possible_name == 'overlapped':
print('[SYSTEM] The name already exists.')
elif len(client_sock.recv(1024).decode()) == 0:
print('[SYSTEM] The server has been disconnected.')
client_sock.close()
os._exit(1)
while True:
if goaltime_hour <= 0 and goaltime_min <= 0:
print('Please enter the time')
continue
elif (str(type(goaltime_hour)) != "<class 'int'>") or (str(type(goaltime_min)) != "<class 'int'>"):
print("Please enter the int")
continue
else: break
pw = input("enter password")
client_sock.send((str(pw)).encode())
print("login completed. \n ")
break
服務器
class timeuser:
name: str=None
goaltime_hour: int=None
goaltime_min: int=None
goaltime_sec: int=None
currsecond: int=0
while True:
count = count 1
conn, addr = server_sock.accept()
client=timeuser()
while True:
username = conn.recv(1024).decode()
if not username in member_name_list:
conn.send('yes'.encode())
break
else:
conn.send('overlapped'.encode())
client.name = username
clientHour = int(conn.recv(1024).decode()) # ????
client.goaltime_hour = clientHour
clientMin = int(conn.recv(1024).decode()) # ???
client.goaltime_min = clientMin
clientsec = int(conn.recv(1024).decode()) # ???
client.goaltime_sec = clientsec
你可以在這里看到整個代碼: https ://github.com/whataLIN/Pysoc_myStudyTimer
我洗掉了除小時和名稱之外的所有其他資料傳輸和接收程序,然后它作業正常。我想得到沒有錯誤的其他資料..
uj5u.com熱心網友回復:
錯誤 10053 是“連接重置”( WSAECONNRESET)。這意味著服務器關閉了它的套接字。
這可能是因為客戶端發送!enter并且服務器嘗試將其作為數字讀取并崩潰。如果您查看運行服務器的終端,您會看到它崩潰。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/525374.html
標籤:Python插座
下一篇:DartUDP套接字不會超時
