threads check socket

N

NighterNet

I been trying to find a way to check the socket is open or not. The
thread are in a group and loop if the sockets are open. If they are
not open delete the thread and remove the group. I need on this.
 
G

Gabriel Genellina

I been trying to find a way to check the socket is open or not. The
thread are in a group and loop if the sockets are open. If they are
not open delete the thread and remove the group. I need on this.

What means an "open socket"? Do you want to detect whether the other side
closed the connection? In that case reading from the socket returns an
empty string.

Regarding the "threads in a group", I don't understand what you mean. But
in general, you don't delete a thread, you just return from its run()
method and the thread finishes execution.
 
N

NighterNet

What means an "open socket"? Do you want to detect whether the other side  
closed the connection? In that case reading from the socket returns an  
empty string.

Regarding the "threads in a group", I don't understand what you mean. But  
in general, you don't delete a thread, you just return from its run()  
method and the thread finishes execution.

Thread added into the array. Well this thread when user leave the
server want to make sure it not in used so that I can reuse it some
how or move into another array.

Need to know the thread speed that need for game server timer to
control it. Don't want it too fast or slow for the game server.
fps = 30
def run(self):
while True:
self.gametime += 1
if self.gametime > 10000000/fps:
self.gametime = 0;
 
G

Gabriel Genellina

Thread added into the array.

Which array?
Well this thread when user leave the
server want to make sure it not in used so that I can reuse it some
how or move into another array.

Sorry but it's hard to help if you don't provide enough background. Looks
like you're developing a game server; maybe this story is relevant to you:
http://comments.gmane.org/gmane.comp.python.general/627319

Assuming you're talking about TCP: when the client closes the connection
gracefully, you get an empty string '' when reading from the socket. If
the client loses the connection abruptly (the power goes down, the network
is broken, the process is killed...) you get no indication of that. You
may need to implement some mechanism (a PING? query/response, or perhaps
the client must send an "I'm alive!" message once each N minutes; no
answer means it's down and the server closes the connection).
Need to know the thread speed that need for game server timer to
control it. Don't want it too fast or slow for the game server.
fps = 30
def run(self):
while True:
self.gametime += 1
if self.gametime > 10000000/fps:
self.gametime = 0;

What's this code used for, apart from sucking lots of CPU power?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,201
Messages
2,571,048
Members
47,649
Latest member
MargaretCo

Latest Threads

Top