I played a bit with WebSockets and started to implement a tiny chat. Last time I did something like this was when there was no such thing as threads and computers had single core. I started to think how to implement it with todays programming patterns but I didn't come to any final conclusion.How you implement chat's main functionality in today's technics in higher level?I now have context Server, Socket and User. User has states Undefined, Connected, InChat, ToBeDisconnected, Disconnected, My main problem is the user maintenance:If user hasn't said hello in 5 seconds after connection was opened -> disconnectUser is not replied to ping with pong at all or at least 2 minutes -> disconnectUser has been connected over 12 hours -> disconnectUser haven't been assigned profile (nickname and/or other details) after 5 minutes of connect -> disconnectSome other program specific flag that kicks out user is triggered -> disconnect My current implementation is like how it was done in olden days. ie. I have while(serverRunning) {   foreach(socket in allSockets)  {    user = allUsers.findUserBySocket(socket);     doMaintenance(user);  }}Now this runs far too many times and locks and blocks allUsers and allSockets way too much.How this is implemented today? Like this for example?Socket connects Add to allSockets Add to allUsers Start per-user thread that runs every x seconds and runs user.doMaintenance()?Or there's per-user queue that gets injected with actions like doPongCheckAction, doProfileTimeoutCheckAction, etc every x seconds (also needs per-user thread which constantly empties user's queue)?Or there's Maintenance thread that runs every x second after last run and iterates through allUsers (a bit like current implementation)?Or there's thread that injects actions to all users queues when there's been too long when same kind of action were ran and other thread that iterates through all users and empties user's queue?Or something else or which is not even based on queues? :)
Implementing chat in 2013
architecture;real time