listening socket doesnt answer
Alexander K
ak42 at altavista.com
Mon Oct 2 03:03:43 EDT 2000
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()
--------------------------
this is what i write in the interpreter:
>>> from socket import *
>>> s = socket(AF_INET, SOCK_STREAM)
>>> s.connect('e303.vildanden.afb.lu.se', 1234)
Traceback (innermost last):
File "<stdin>", line 1, in ?
socket.error: (111, 'Connection refused')
what is wrong???
this is what i get from a netstat:
[alex /home/alex/python]# netstat -a | grep 1234
tcp 0 0 0.0.0.1:1234 *:* LISTEN
here i notice one strange thing. the local address part. it says
"0.0.0.1:1234". but all other services in LISTEN mode have a "*"
instead of "0.0.0.1". what is going on?
and one more question:)
where do i best learn about the different address/protocol
families, and how they decide the format for the .bind() method?
when dealing with a inet/stream socket i pass a tuple to bind,
right? like this .bind((hostname, port)) where hostname is a
string and port an integer.
but in the other cases?
tia / alex k
--
.
.
... ~~~:[ com dot altavista at ak42 ]:~~~ ...
More information about the Python-list
mailing list