wrong socket: OSError: [WinError 10057] Since the socket is not connected and (when a call to send a sendto datagram socket) does not provide an address, a request to send or receive data is not accepted.

Error code

#server端
import socket
import struct

sk=socket.socket()
sk.bind(('127.0.0.1',8080))
sk.listen()
conn,addr=sk.accept()
str_len1=struct.unpack('i',conn.recv(4))[0]
print(sk.recv(str_len1))
str_len2=struct.unpack('i',conn.recv(4))[0]
print(sk.recv(str_len2))
conn.close()
sk.close()

And because the socket is not connected (when a call to send a sendto datagram socket) is not provided ([WinError 10057]: In the above problem areas marked red, sk is the socket where it appeared OSError address, a request to send or receive data is not accepted.) error,

Solution: sk only need to change the conn to

Guess you like

Origin www.cnblogs.com/HByang/p/11332828.html