server side socket program hangs
anuradha.k.r at sify.com
anuradha.k.r at sify.com
Fri Oct 10 01:02:03 EDT 2003
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.
"Anthony McDonald" <tonym1972/at/club-internet/in/fr> wrote in message news:<3f74571f$0$20952$7a628cd7 at news.club-internet.fr>...
> <anuradha.k.r at sify.com> wrote in message
> news:57efaf35.0309260215.5ddd5734 at posting.google.com...
> > hi,
> > i am writing a socket program in python,both client side and server
> > side.I've written the client side which is working perfectly
> > fine(checked it against server program written in C).but as for my
> > server program written in python it simply hangs.it does not show any
> > error also.I've tried sample programs available .I don understand what
> > the reason is as i am quite new to it.
> > here is teh server side program:
> >
> > ///////////////////////
> > from socket import *
> > import socket
> > import sys
> >
> > HOST = '' #any address
> > PORT = htons(9999) #same port address as client
> >
> <snip code>
> >
> > can someone tell me what the problem is?
>
> Your applying a function designed to simplyfy transfering IP addresses to a
> literal value you want to use for your port. The following should show the
> effect thats now happening.
>
> PythonWin 2.3.1 (#47, Sep 23 2003, 23:47:32) [MSC v.1200 32 bit (Intel)] on
> win32.
> Portions Copyright 1994-2001 Mark Hammond (mhammond at skippinet.com.au) - see
> 'Help/About PythonWin' for further copyright information.
> >>> import socket
> >>> socket.htons(9999)
> 3879
> >>>
More information about the Python-list
mailing list