server side socket program hangs

anuradha.k.r at sify.com anuradha.k.r at sify.com
Thu Oct 16 06:08:44 EDT 2003


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

////////////////
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))
    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.



anuradha.k.r at sify.com wrote in message news:<57efaf35.0310142225.2b0fc8b4 at posting.google.com>...
> hi,
> i've posted my doubt on my server program written in python.i am not
> able to communicate with any client.My server program does not even
> create a socket.can someone tell me what the problem is?
> thanx,
> AKR
> 
> 
> anuradha.k.r at sify.com wrote in message news:<57efaf35.0310132112.6ecd9840 at posting.google.com>...
> > hi,
> > My one problem is solved,python server no more hangs,but my main
> > purpose still remains unsolved,my client is not able to establish
> > connection.my client is a C program running on a windows machine.On
> > running the python program,in the python shell i get this way
> > >>>
> > (cursor)
> > 
> > i assumed my server is waiting for a connection,but my client did not
> > connect,it failed.
> >      I tried debugging the python program using the step by step debug
> > control.it moves till def __init__(Self,parent):
> > and stops(seems to be waiting).It does not move to the next line.
> > Can you tell me what is happening? and what is the problem with my
> > server program?Sorry for the trouble,
> > thanx
> > AKR.
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > "Anthony McDonald" <tonym1972/at/club-internet/in/fr> wrote in message news:<3f8670c7$0$12567$7a628cd7 at news.club-internet.fr>...
> > > <anuradha.k.r at sify.com> wrote in message
> > > news:57efaf35.0310092102.1231b120 at posting.google.com...
> > > > hi,
> > > >   was stuck with another work.now bac to python program.
> > > > i tried out using
> > > > PORT = socket.htons(9999)
> > > >
> > > > it still doesn't work.here is the code.it still hangs.can some one
> > > > tell me what could be te problem?
> > > >
> > > > #from socket import *
> > > > import socket
> > > > import sys
> > > >
> > > > HOST = ''       #any address
> > > > PORT = socket.htons(9222)        #same port address as client
> > > >
> > > > class Sock:
> > > >      def __init__ (self,parent):
> > > >           try:
> > > >                self.s = socket(AF_INET,SOCK_STREAM)
> > > >           except socket.error:
> > > >                 print 'socket not created'
> > > >           try:
> > > >                self.s.bind((HOST,PORT))
> > > >           except self.error:
> > > >                print 'error in bind'
> > > >           try:
> > > >                self.s.listen(5)
> > > >           except self.error:
> > > >                print 'error in listen'
> > > >           conn, addr = self.s.accept()
> > > >              #  print 'Connected by',`addr`
> > > >           while 1:
> > > >                data = conn.recv(1024)
> > > >                if not data: break
> > > >                conn.send(data)
> > > >           conn.close()
> > > >
> > > > thanx,
> > > > AKR.
> > > >
> > > Sorry for my brief answer last time, but I had hoped the code fragment I
> > > posted would explain what was happening with your code.
> > > 
> > > Your code is almost a verbatum copy of the Python example, except you've
> > > chosen to massage the port value using the HTONS function. So for most
> > > architectures the port value 9999 or 9222 would be changed to somewhere in
> > > the 3xxx port range. Any client trying to connect on those ports will fail.
> > > Hence you noted success on a C server which isn't using that function, but
> > > failure on your Python server which is. The solution is to just assign the
> > > port value you want unchanged.




More information about the Python-list mailing list