Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 4th, 2004, 04:41 AM
dbickett dbickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 34 dbickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.socketsocket.AF_INET socket.SOCK_STREAM )

sock.bind( ( 'localhost' 5376 ) )

sock.listen)

print 
"Server initiated; entering acceptance loop..."

while 1:
    
conn sock.accept()

    
temphndl sockwatchconn recvd )

    
slaves.appendtemphndl )

    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 sockwatchthreading.Thread ):
    
def __init__self sockethndl queuehndl ):
        
self.socket sockethndl
        self
.queue queuehndl
        
print "Sockwatch instance created..."
        
threading.Thread.__init__self )
    
def runself ):
        
breaksess 0
        
while not breaksess:
            
data self.recvcmdself.socket )
            if 
not data == 0:
                
self.queue.putdata )
                print 
"Put data into queue..."
            
else:
                
breaksess 1
    def recvcmd
sockethndl ):
        
breakloop 0
        result 
''
        
while not breakloop:
            
byte sockethndl.recv)
            if 
byte == "=":
                
breakloop 1
            
else:
                
result += byte
        
return result 


does anyone know why this is happening?

Beeyah

Reply With Quote
  #2  
Old August 4th, 2004, 06:52 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
The first thing that jumps out is that socket.accept() returns a tuple, not a socket object:

Quote:
Accept a connection. The socket must be bound to an address and listening for connections. The return value is a pair (conn, address) where conn is a new socket object usable to send and receive data on the connection, and address is the address bound to the socket on the other end of the connection.


So self.socket in sockwatch() will be a tuple. The reason I mention this is because you try and call the recv() method on this tuple in recvcmd(), which should cause an error.

You might also want to make the while loop simpler by doing while True and using break when you need to exit.

Have fun,

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old August 4th, 2004, 07:07 AM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,536 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 18 h 3 m 4 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
You might also find the asyncore module insteresting, since its was made for the kind of thing you're doing (or seem to be doing) .

Reply With Quote
  #4  
Old August 4th, 2004, 01:36 PM
dbickett dbickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 34 dbickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
Thank you very much for your response However, I had still been having problems with receiving data even after making the changes you suggested, so i decided to make it print a harmless message as soon as sockwatch entered the run() method. the problem is, the message is never printed. is there anything in my code that would prevent run() from executing?

Reply With Quote
  #5  
Old August 4th, 2004, 01:38 PM
dbickett dbickett is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 34 dbickett User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
nevermind :D I realize now I didn't start() my thread :P

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > written base code for a server -- encountered errors; need help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT