Error when executing the library reference echo server example

D

diego.martin.a

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)
 
C

Chris

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 ?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top