listening socket doesnt answer

Maurizio Turatti mturatti at yahoo.com
Mon Oct 2 05:14:40 EDT 2000


Alexander K wrote:
> 
> hello!
> 
> i made this script that opens a socket and listens. then i start
> the python interpreter in another xterm (i run linux 2.2.16,
> with python 1.52) and try connecting to that socket.
> but i get a 'Connection refused'...
> funny thing is that it used to work. and i am as sure as i can
> that i wrote the sockets in this way then too.
> 
> the script:
> --------------------------
> from socket import *
> 
> hostname = gethostbyname(gethostname())[0]
> port = 1234
> 
> s = socket(AF_INET, SOCK_STREAM)
> s.bind((hostname, port))
> s.listen(5)
> print 'listening', port
> (ps, add) = s.accept()
> --------------------------
> 

What happens if you use  s.bind('', port) ? I don't see any reason to
bind the name for the server other than "localhost", but I can be wrong.

	Maurizio



More information about the Python-list mailing list