Error when executing the library reference echo server example

diego.martin.a at gmail.com diego.martin.a at gmail.com
Mon Dec 10 07:16:03 EST 2007


Hi. Python newbie speaking,

I've copy/pasted the example of the echo server that comes in the IDLE
documentation ("Python Library Reference" section 17.2.3) to see how
the sockets work. The only change I've made is in the host address
which I've set to 'localhost' in the client. You can see the complete
code below the message.

When I run it I get the following error:
     Traceback (most recent call last):
          File "C:\Python25\eclient.py", line 11, in <module>
          data = s.recv(1024)
     error: (10053, 'Software caused connection abort')

Is the example wrong? In this case, Where can I find a working
example? Have I messed up the example putting 'localhost'? (don't
think so, because I tried with '127.0.0.1' and I got the same error).
And the big one, Why I get the error and how can I avoid it in future
applications?

Lot of thanks in advance!!

---CODE---
# Echo server program
import socket

HOST = ''                 # Symbolic name meaning the local host
PORT = 50001              # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(10)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
    data = conn.recv(1024)
    if not data: break
    conn.send(data)
conn.close()
_______________________________

# Echo client program
import socket

HOST = 'localhost'    # The remote host
PORT = 50001              # The same port as used by the server
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.send('Hello, world')
data = s.recv(1024)
s.close()
print 'Received', repr(data)




More information about the Python-list mailing list