On 27 Mar 2013, at 08:11, Holger Hans Peter Freyther <[email protected]> wrote:

> On Tue, Mar 26, 2013 at 09:08:09PM +0100, Sven Van Caekenberghe wrote:
> 
>> Maybe I am telling you things you already know, but TCP and UDP are 
>> fundamentally different. UDP is really one-shot, try-and-hope, completely 
>> asynchronous. In networking you generally only get a ConnectionClosed when 
>> you actually read or write (and even then ;-). 
> 
> Yes, but at least for the unix platform on close the aio/select handler is
> removing the socket from the registration. So there is no way to read the
> zero from the dead socket. :)
> 
>> For your concrete question (2): just start a reading process, wrap it in a 
>> handler and clean up. For UDP this will never happen: you will keep on 
>> reading nothing. For TCP reading will eventually fail if the other end 
>> disappears.
> 
> Do you have an example for "handler and clean up"? I resorted to code
> like this for now in my 'blocking' read.
> 
>       [self dataAvailable] 
>           whileFalse: [[self waitForDataFor: 10] on: ConnectionTimedOut do: 
> []].
> 
> But I have not ported my client code so I don't know if the above is
> working or not. This way I will get the ConnectionClosed exception at
> least within 10 seconds.
> 
> thank you
> 
> holger

It is still not clear to me if this is for UDP or TCP, I would be surprised of 
#dataAvailable or #waitForData: actually work for UDP. I gave you some pointers 
to examples that do work. Your code snippet looks reasonable to me, but I would 
set timeouts on the socket(streams) and use regular read/write operations and 
then loop.

Sven


Reply via email to