Hi all,
I'm a squeak newbie esp. wrt sockets. I have a telnet connection open to squeak and run this code on the connected socket:
(Delay forSeconds:10) wait. socket isOtherEndConnected ifTrue: socket sendData: 'hi there'.
This works, including if I close the other end before I get to this code (no send is then attempted).
But the following code gets a debug message, 'send data timeout; data not sent' when I close the other end well before the test:
10 timesRepeat: [ (Delay forSeconds:10)wait. socket isOtherEndConnected ifTrue: socket sendData: 'hi there'. ]
I'm going bonkers trying to figure this out. With tests of various permutations the failure seems to happen anytime the test is inside a block.
I am running RedHat Linux 7.1, squeak vm 3.0pre2 and image updated to #4343. I get the same result with the latest vm compiled from Lex Spoon's patches page.
Any ideas?
Thanks in advance,
Mike
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
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:
Realize that #isConnected and such are optimisitic.
Allow for every send or recieve to fail. Corollary: don't use
routines that generate their own error messages internally.
-Lex
squeak-dev@lists.squeakfoundation.org