954,510 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

socket.error: [Errno 107] Transport endpoint is not connected

I'm trying to understand socket programming in python by experimenting a little. I'm trying to create a server that you can connect to by telnet and that echoes what you type in the telnet prompt. I don't want to start using threads just yet. This is my code.

import socket

host = "127.0.0.1"
port = 8080

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

sock.bind((host,port))
sock.listen(1)
remote, address = sock.accept()
print "Connection from", address 



while True:
    data = sock.recv(1024)
    remote.send(data)

The server starts without errors, but when I connect with the telnet client I get, on the client side: > telnet 127.0.0.1 8080
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.

and on the server side: > python server_test.py
Connection from ('127.0.0.1', 35030)
Traceback (most recent call last):
File "server_test.py", line 16, in <module>
data = sock.recv(1024)
socket.error: [Errno 107] Transport endpoint is not connected

Can anyone tell me what this error comes from and how to solve it?

hadoque
Newbie Poster
10 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

Stack Overflow offers the advice to RTFM. I can only agree...

griswolf
Veteran Poster
1,165 posts since Apr 2010
Reputation Points: 344
Solved Threads: 256
 

Great! Solved it...

hadoque
Newbie Poster
10 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

Hi,
Can you tell me please how did you fix the problem ?!
Thanks!

HorSiZe
Newbie Poster
1 post since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

Sorry, I don't quite remember and right now I don't have time to revisit the problem (master thesis deadline on thursday :) ) . What I do remember is that I solved it by following the advice in the link; Read the manual...

hadoque
Newbie Poster
10 posts since May 2010
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: