help with Socket>>isOtherEndConnected

Michael Fremont mike at zorch.com
Fri Sep 28 14:15:30 UTC 2001


Thanks, Lex, excellent point, and I can do that.  But to push the point 
further: this doesn't seem like a failure of Unix, since isOtherEndConnected 
works when it isn't called from inside a block.  So I wonder if something 
more serious is broken?

Best,

Mike

On Thursday 27 September 2001 09:28 pm, you wrote:
> > 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