Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Socket programming

by SuicideJunkie (Vicar)
on Nov 12, 2008 at 15:34 UTC ( #723192=note: print w/replies, xml ) Need Help??


in reply to Socket programming

Please try to edit your posts to add/correct things instead of making new ones with the same question. http://perlmonks.org/?node_id=723152

It is definitely possible to have sockets die without notice, such that the while loop won't exit. I suffered that when I wrote a telnet-based multiplayer market trading game.

What I did was to select from the current connections, and carefully read a byte at a time.
Once there is enough to act on, I call whatever functions need calling. (If not, buffer the input so far, and loop back to the select)

If one of the connections dies silently and unexpectedly, the select won't pick it to read from since there is no more input to read. After a few minutes of no activity, the dead/timed-out connections can be closed.

Replies are listed 'Best First'.
Re^2: Socket programming
by Illuminatus (Curate) on Nov 12, 2008 at 16:11 UTC
    If the connection is via a WAN or the Internet, then what you are describing can occur. Within a local network, it is much less likely. This is a TCP socket. When either side receives a FIN, the result in the application is an EOF. When a process dies, in almost all instances, open sockets are closed by the OS, resulting in a FIN going to the remote side. On a LAN, the receipt of this is almost certain. On a WAN, intervening equipment/hops can cause packet or session loss.
      Indeed it is a rare occurrence, but in a single-threaded server, one eternal wait event is all that is required to take the system down.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://723192]
help
Chatterbox?
[james28909]: how come it is so easy for me to not care what others think while others will mute themselves because they are scare they will be called ignorant or stupid
[james28909]: do you relize how shrodinger felt when he was describing the quantum world? what about neils bohr?
[holli]: it's probably the autist in you. I am like that too, no fucks given about what others think about me
james28909 checks, yep... htere are no fucks to give
[james28909]: another thing i am sick of is hurting others feelings

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2017-12-15 14:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What programming language do you hate the most?




















    Results (433 votes). Check out past polls.

    Notices?