
August 4th, 2004, 04:41 AM
|
|
Contributing User
|
|
Join Date: Jul 2004
Posts: 34
Time spent in forums: < 1 sec
Reputation Power: 5
|
|
|
written base code for a server -- encountered errors; need help
Okay, so I'm working with two other people to make this service, and my job is making the server. However I'm having problems: first of all, for some reason it can't handle two clients, and I need someone to show me what I'm doing wrong. Actually, we'll just keep it at the for now. So let me show you my main acceptance loop:
PHP Code:
sock = socket.socket( socket.AF_INET , socket.SOCK_STREAM )
sock.bind( ( 'localhost' , 5376 ) )
sock.listen( 5 )
print "Server initiated; entering acceptance loop..."
while 1:
conn = sock.accept()
temphndl = sockwatch( conn , recvd )
slaves.append( temphndl )
print "[" + time.strftime("%X") + "] Accepted client"
So basically, it accepts the connection and sends a handle down to my "sockwatch" thread, which waits for input from the client. However, when I connect to my server again, the first connection is killed. The idea is it supports countless connections, but anyway, moving on, here is my sockwatch thread:
PHP Code:
class sockwatch( threading.Thread ):
def __init__( self , sockethndl , queuehndl ):
self.socket = sockethndl
self.queue = queuehndl
print "Sockwatch instance created..."
threading.Thread.__init__( self )
def run( self ):
breaksess = 0
while not breaksess:
data = self.recvcmd( self.socket )
if not data == 0:
self.queue.put( data )
print "Put data into queue..."
else:
breaksess = 1
def recvcmd( sockethndl ):
breakloop = 0
result = ''
while not breakloop:
byte = sockethndl.recv( 1 )
if byte == "=":
breakloop = 1
else:
result += byte
return result
does anyone know why this is happening?
Beeyah
|