Error when executing the library reference echo server example

Chris cwitts at gmail.com
Mon Dec 10 07:35:06 EST 2007


On Dec 10, 2:16 pm, diego.marti... at gmail.com wrote:
> 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)

I copy/pasted your code and ran it without any faults.  Are you using
any firewall software that could be causing the connection to be
terminated ?



More information about the Python-list mailing list