help with Socket>>isOtherEndConnected

Lex Spoon lex at cc.gatech.edu
Fri Sep 28 04:28:10 UTC 2001


> 10 timesRepeat:
> 	[
> 	(Delay forSeconds:10)wait.	
> 	socket isOtherEndConnected
> 		ifTrue: socket sendData: 'hi there'.
> 	]
> 

It's hard if not impossible on most Unices to decide whether a socket is
open or not, short of trying to read or write from it.  However, this
actually isn't a big deal: a network connection might die at any time,
including between the time you ask whether it's connected and the time
you try to do something with it.  So, your code needs to allow for this
kind of failure, anyway.  But if you handle this failure, you don't
really need to check all the time before you try to use the socket --
just use it and see if it works!

Granted, this error message from sendData: isn't a very good one.  It
should probably mention the possibility that the connection has closed.


Overall, for more serious networking code:

	1. Realize that #isConnected and such are optimisitic.

	2. Allow for every send or recieve to fail.  Corollary: don't use
routines that generate their own error messages internally.


-Lex




More information about the Squeak-dev mailing list