PC Review


Reply
Thread Tools Rate Thread

Asynch Sockets over UDP: How do you Know when a socket dissconnects

 
 
DaTurk
Guest
Posts: n/a
 
      12th Jun 2006
I have this application that has one sender, and multiple receivers,
the receivers are subscribing to a multicast group to which the sender
is sending information synchronously, while the receivers are receiving
asynchronously. My issue, is that if the if the receiver's socket
disconnects for any reason I want to be able to detect it and attempt
to reconnect.

Although I'm uncertain what to look for. I thought the receiver would
receive 0 bytes, but this is only with TCP. I would also like to
implement a time out where each attempt to reconnect is stalled for
that amount of time before trying to reconnect. Any help would be
appreciated.

 
Reply With Quote
 
 
 
 
Greg Young
Guest
Posts: n/a
 
      13th Jun 2006
There is no such thing as a connection in UDP ..
http://en.wikipedia.org/wiki/Connectionless_protocol

Not quite sure what you are looking for?

Cheers,

Greg Young
MVP - C#
http://codebetter.com/blogs/gregyoun

"DaTurk" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>I have this application that has one sender, and multiple receivers,
> the receivers are subscribing to a multicast group to which the sender
> is sending information synchronously, while the receivers are receiving
> asynchronously. My issue, is that if the if the receiver's socket
> disconnects for any reason I want to be able to detect it and attempt
> to reconnect.
>
> Although I'm uncertain what to look for. I thought the receiver would
> receive 0 bytes, but this is only with TCP. I would also like to
> implement a time out where each attempt to reconnect is stalled for
> that amount of time before trying to reconnect. Any help would be
> appreciated.
>



 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      13th Jun 2006
"DaTurk" <(E-Mail Removed)> wrote:

> I have this application that has one sender, and multiple receivers,
> the receivers are subscribing to a multicast group to which the sender
> is sending information synchronously, while the receivers are receiving
> asynchronously. My issue, is that if the if the receiver's socket
> disconnects for any reason I want to be able to detect it and attempt
> to reconnect.
>
> Although I'm uncertain what to look for. I thought the receiver would
> receive 0 bytes, but this is only with TCP. I would also like to
> implement a time out where each attempt to reconnect is stalled for
> that amount of time before trying to reconnect. Any help would be
> appreciated.


You need to send keep-alive packets of some kind. UDP is connectionless,
so there is no "connection" to detect.

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
DaTurk
Guest
Posts: n/a
 
      13th Jun 2006
Would it make sense then, since there esentially won't be any
disconnect, to just check for a SocketException, and assume that if we
catch one that the socket is unable to send receive, and attempt to
reconnect?
That's what I'm doing now, but I haven't tested it.

 
Reply With Quote
 
Barry Kelly
Guest
Posts: n/a
 
      14th Jun 2006
"DaTurk" <(E-Mail Removed)> wrote:

> Would it make sense then, since there esentially won't be any
> disconnect, to just check for a SocketException, and assume that if we
> catch one that the socket is unable to send receive, and attempt to
> reconnect?


UDP is unreliable and *connectionless*. It makes a best-effort to
deliver, but the packets may simply disappear into the ether. Any errors
you get may disappear with the next packet you send, but on the other
hand, the packets might simply have been dropped somewhere along the
way.

There is no "connection" process, so attempting to "reconnect" doesn't
actually do *anything*. That is, at the low level of the BSD socket API,
calling "connect" on a connectionless (i.e. UDP over IP) socket that you
already called "connect" on, does *absolutely* *nothing*.

The Windows API docs have this to say (connect function, Winsock):

---8<---
For a connectionless socket (for example, type SOCK_DGRAM), the
operation performed by connect is merely to establish a default
destination address that can be used on subsequent send/ WSASend and
recv/ WSARecv calls.
--->8---

There is no connection established when you call connect, and no bytes
leave your machine when you call connect.

If you *need* to know if the other application is listening, it either
has to echo your packets in some way, or send back a heartbeat of some
kind.

-- Barry

--
http://barrkel.blogspot.com/
 
Reply With Quote
 
DaTurk
Guest
Posts: n/a
 
      14th Jun 2006
Thanks for the reply, I think I didn't use the correct words, when I
say reconnect, I really mean set the socket up to receive
informationfrom the given multicast group
i.e. Bind, Subscribe to MultiCast Group, BeginReceive.

Like I said, I'm just expecting a Socket exception if it happens. Then
I attempt to go through the motions to put the socket back in a
position to receive information from the Multicast group.

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Win Forms GUI locks up with Asynch Socket Callback / WinForms.Delegate Dave Microsoft C# .NET 3 15th Aug 2007 07:28 PM
ASynch sockets race =?Utf-8?B?cGF1bCBtb29yZQ==?= Microsoft Dot NET Framework 1 7th Jun 2007 12:57 AM
having trouble with asynch sockets =?Utf-8?B?TWljaGFlbCBFdmFuY2hpaw==?= Microsoft C# .NET 1 14th May 2005 05:22 PM
Gracefully exiting blocking or asynch socket receive =?Utf-8?B?RGFuIEtlbGxleQ==?= Microsoft C# .NET 1 18th Apr 2005 11:24 AM
How to throw exception from asynch socket callback Barry Anderberg Microsoft C# .NET 1 9th Jan 2004 04:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:38 PM.