socket question

  • Thread starter Philippe C. Martin
  • Start date
P

Philippe C. Martin

Hi,

I am following a few tutorial and this howto:


*************************************************************
............
What happens in the web server is a bit more complex. First, the web
server creates a "server socket".

#create an INET, STREAMing socket
serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
#bind the socket to a public host,
# and a well-known port
serversocket.bind((socket.gethostname(), 80))
#become a server socket
serversocket.listen(5)

A couple things to notice: we used socket.gethostname() so that the
socket would be visible to the outside world. If we had used s.bind(('',
80)) or s.bind(('localhost', 80)) or s.bind(('127.0.0.1', 80)) we would
still have a "server" socket, but one that was only visible within the
same machine.
............
*************************************************************

My problem is that I cannot connect to my server if the client is not on
the same PC (although I'm doing the above).
Also:
1) my server has more than one IP addresses
2) my server does not have any DNS name


.... so I want to connect to an IP address that I can ping but has no
name.


How can I do that ?

Regards,

Philippe
















--
***************************
Philippe C. Martin
SnakeCard LLC
www.snakecard.com
***************************
 
D

Diez B. Roggisch

A couple things to notice: we used socket.gethostname() so that the
socket would be visible to the outside world. If we had used s.bind(('',
80)) or s.bind(('localhost', 80)) or s.bind(('127.0.0.1', 80)) we would
still have a "server" socket, but one that was only visible within the
same machine.

This is wrong. There is a difference between passing '' and 'localhost'. The
latter binds the socket only to the ip 127.0.0.1, where '' binds it to all
available ips.
My problem is that I cannot connect to my server if the client is not on
the same PC (although I'm doing the above).
Also:
1) my server has more than one IP addresses
2) my server does not have any DNS name
... so I want to connect to an IP address that I can ping but has no
name.
How can I do that ?

Pass the ip as hostname (as string like "192.168.1.10")
 
K

Kartic

Does the machine running the server code also have a firewall installed
that blocks access to the server port from outside? That is the only
possibility I can think of that prevents a non-local client from
connecting.

Also, please do a netstat -a on the machine running the server and see
the IP addresses to which the listening port is bound.

Thanks,
-Kartic
 
P

Philippe C. Martin

Thanks, it was a bind problem: socket.gethostname() returns 'localhost'
where '' is was was needed.

Regards,

Philippe
 

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

Forum statistics

Threads
473,982
Messages
2,570,185
Members
46,738
Latest member
JinaMacvit

Latest Threads

Top