473,401 Members | 2,068 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,401 software developers and data experts.

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

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.

Jun 12 '06 #1
5 1987
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" <mm******@hotmail.com> wrote in message
news:11**********************@f6g2000cwb.googlegro ups.com...
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.

Jun 12 '06 #2
"DaTurk" <mm******@hotmail.com> 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/
Jun 13 '06 #3
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.

Jun 13 '06 #4
"DaTurk" <mm******@hotmail.com> 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/
Jun 14 '06 #5
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.

Jun 14 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
3
by: Bernd | last post by:
hi, is it possible to use a Socket (proto_udp) and recieve icmp messages ? what i want to do is, send a datagram to a remote host/port and check if the host replies with port_unreachable (i...
0
by: Gregory Hassett | last post by:
I am writing a loop which will listen on a given port for incoming UDP packets. If the UDP sender (client), terminates abnormally, then my call to socket.BeginReceiveFrom throws a SocketException....
4
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
by: Adam Honek | last post by:
Hello, Can someone pinpoint me to a reliable link relating to sockets and how they are implemented to allow client/server communication? I'm finding quite a few but very few actually explain...
5
by: Dan Ritchie | last post by:
I've got a client/server app that I used to send large amounts of data via UDP to the client. We use it in various scenarios, one of which includes rendering a media file on the client as it is...
0
by: J008 | last post by:
Just looking for some insight as to why the callback "BeginReceiveFromCallback" is not being called in my "Receive" Subroutine below (when I call BeginReceiveFrom). I am trying to read data...
6
by: buc | last post by:
Why does VB.NET UDP sockets send data on random ports?. If I set a simple socket up to transmit a UDP packet on a port, look at the packet with a sniffer, the actual packets source port and...
6
by: 7stud | last post by:
My question pertains to this example: #!/usr/bin/env python import socket, sys, time host = sys.argv textport = sys.argv s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.