SocketException question

R

Rainer Queck

Hello NG,

in my application I get a SocketException in my receive callback method, if
the remote socket closes.
What would be the right way to treat this exception?

I want to keep my socket working, so that I can continue to receive
messages from the remote application, as it comes back online.
My problem at the moment is, that if I call the udpClient.BeginReceive in
this moment, I again get the SocketException and from now on can't receive
any more messages on the socket.

Thanks for help and infos.

Regards
Rainer Queck
 
P

Pavel Minaev

Hello NG,

in my application I get a SocketException in my receive callback method, if
the remote socket closes.

Technically, a remote UDP socket cannot "close" from your perspective,
since there's no established connection channel as such.
What would be the right way to treat this exception?

Depends on what the exception is, really...what is
SocketException.ErrorCode for the one you get?
 
R

Rainer Queck

Hello Pavel,

Technically, a remote UDP socket cannot "close" from your perspective,
since there's no established connection channel as such.

Depends on what the exception is, really...what is
SocketException.ErrorCode for the one you get?
<
The error code is 10054 and the message - translated from german - is:
"A existing connection was closed by the remote host"

Rainer
 
P

Pavel Minaev

Hello Pavel,


Technically, a remote UDP socket cannot "close" from your perspective,
since there's no established connection channel as such.


Depends on what the exception is, really...what is
SocketException.ErrorCode for the one you get?
<
The error code is 10054 and the message - translated from german - is:
"A existing connection was closed by the remote host"

Hm... apparently, if you do a Send, and get the "ICMP port
unreachable" response, this manifests itself as an error on the next
Receive you try to do on the same socket. MSDN claims that a socket
is unusable once that happens, so you may have to recreate it entirely
on the same endpoint (once the client goes back online, it shouldn't
make any difference anyway, so long as the endpoint is the same).
 
R

Rainer Queck

Hello Pavel,

Hm... apparently, if you do a Send, and get the "ICMP port
unreachable" response, this manifests itself as an error on the next
Receive you try to do on the same socket. MSDN claims that a socket
is unusable once that happens, so you may have to recreate it entirely
on the same endpoint (once the client goes back online, it shouldn't
make any difference anyway, so long as the endpoint is the same).
<
Basically I understand what you say, but...
If I start my app and send a udp message to a port which is not opened
(yet) I do get the socket exception (10054).
The confusing part is, that in this case I can call the
udpClient.BeginReceive within the Callback Method, without causing another
SocketException.

If a connection was establische, and then the remote socke closes I can't
call BeginRecieve without causing another (10054).
Why is that?

Regards
Rainer
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top