OSError: [Errno 107] The endpoint of the vehicle is not connected

I am trying to learn how to use sockets in python to communicate between two computers. Unfortunately, I get this error when everything seems to be correct:

OSError: [Errno 107] The endpoint of the vehicle is not connected

When searching on Google, I found that this is due to the fact that the connection may fall. But I run both the client and server parts of the program on the same machine. I tried to connect again from the end of the client, and I get the following:

OSError: [Errno 106] Transport endpoint is already connected

indicating that the previous connection is still intact. I am pretty confused as to what is happening and how to make it work. Here are screenshots that show what I'm trying to do, and the problem:

enter image description here

+4
1

python 3.5.0, : , sock.accept(), :

socket.accept() . . (conn, address), conn - , , - , .

#server
>>> import socket
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sock.bind(("localhost", 8081))
>>> sock.listen(2)
>>> conn, addr = sock.accept()
>>> data= conn.recv(1024).decode("ascii") 

:

#client
>>> import socket
>>> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> sock.connect(("localhost",8081))
>>> sock.send("hi".encode())
2
>>> sock.send("hiiiiiii".encode())
8
>>> sock.send(("#"*1020).encode())
1020
+11

Source: https://habr.com/ru/post/1619686/


All Articles