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 = ""
port = 8080

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

remote, address = sock.accept()
print "Connection from", address 

while True:
    data = sock.recv(1024)

The server starts without errors, but when I connect with the telnet client I get, on the client side:

> telnet 8080
Connected to
Escape character is '^]'.
Connection closed by foreign host.

and on the server side:

> python server_test.py 
Connection from ('', 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?

Recommended Answers

All 4 Replies

Great! Solved it...

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

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...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.