server side socket program hangs

Jørgen Cederberg jorgencederberg at hotmail.com
Thu Oct 16 06:31:32 EDT 2003


anuradha.k.r at sify.com wrote:
> hi,
>   i guess no one is ready to help.neways,my problem is getting
> solved.I 've slightly modified program (one of the samples found in
> the net),now program creates socket,gives bind ,listen success.however
> when i debug at accept it goes to the socket.py,at the accept()
> function definition.and one more step ahead and it hangs.i dono how to
> debug here(inside socket.py).
> 
> here is how the code looks like

Hi ...

the program actually works - but there is a quirk, look below for details.

> 
> ////////////////
> from socket import *
> import sys
> 
> try:
>     s= socket(AF_INET,SOCK_STREAM)
>     print 'socket created'
> except error:
>     print 'socket not created'
> host = ''
> port = 9323
> try:
>     s.bind((gethostname(),port))

You are binding the socket to the hostname of your computer, instead of 
''.  Thus it will only accept connections specific to the hostname and 
therefor fail if you try to connect to localhost or 127.0.0.1


>     print 'bind success'
> except error:
>     print 'bind'
> try:
>     s.listen(1)
>     print 'listen success'
> except error:
>     print 'listen'
> 
> conn,addr = s.accept()
> print 'client is at ', addr
> data = conn.recv(1024)
> conn.send(data)
> conn.close()
> ////////////////////////
>     but i have a feeling that teher's some problem with the port or
> some problem in the program that it hangs.can anyone help?or atleast
> give me few links where i can find a solution,thanx.
> AKR.


Hope this helps
Jorgen





More information about the Python-list mailing list