Ask coding questions

← Back to all posts
Infinite loops on server side
ebest (630)


I got this thing called Pychat, with a server and a client, and I have this idea. I want to add a feature that detects when someone closes their tab, so I can say that they left. I already tried using threading, but it froze the server.

Server Unrelated note: Can someone try hacking the server?


This gives me much trouble.


Answered by samdevz (31) [earned 5 cycles]
View Answer
samdevz (31)

I didn't review the code, but why not have the client send a heartbeat every 10 seconds? Basically, they just send a tiny packet to the server at regular intervals to say "Hey, I'm still here!". If the packet isn't received on time, then you can assume they left / got disconnected and take it from there.

ebest (630)

@samdevz I've actually already done that. It already checks in a while True loop for messages, so I added an extension to that. It only works if someone's on, though.

ebest (630)

@mwilki7 It's not python, so I can't use it.

mwilki7 (1012)

@ebest Use JavaScript to send some sort of HTTP response to the python server and have the server handle the response from there.

ebest (630)

@mwilki7 It's not even a tab, so I can't really monitor it. Also, I don't know https, javascript, or css.