Re: UDPListener: System.Net.Sockets.SocketException



It appears I can keep the program from erroring out by putting the Receive
and Send calls in a try/catch block, but if anyone has advice on how to
eliminate the problem rather than just mask it, that would be great!

--Jon


"J C" <j@xxxxxxxxxxxxxxx> wrote in message
news:OGV4XuuVGHA.4724@xxxxxxxxxxxxxxxxxxxxxxx
Hi,

I'm using UDPClient to make a simple DNS server. I notice that
intermittently and unpredictibly I get:

Unhandled Exception: System.Net.Sockets.SocketException: An existing
connection
was forcibly closed by the remote host
at System.Net.Sockets.Socket.ReceiveFrom(Byte[] buffer, Int32 offset,
Int32 s
ize, SocketFlags socketFlags, EndPoint& remoteEP)
at System.Net.Sockets.UdpClient.Receive(IPEndPoint& remoteEP)
at dnsone_c.CoolUDP.Receive()
at dnsone_c.Program.Main(String[] args)

If I try to restart the server right away, I get:

Unhandled Exception: System.Net.Sockets.SocketException: Only one usage of
each
socket address (protocol/network address/port) is normally permitted
at System.Net.Sockets.Socket.DoBind(EndPoint endPointSnapshot,
SocketAddress
socketAddress)
at System.Net.Sockets.Socket.Bind(EndPoint localEP)
at System.Net.Sockets.UdpClient..ctor(IPEndPoint localEP)
at dnsone_c.CoolUDP.Receive()
at dnsone_c.Program.Main(String[] args)

After about a minute, this goes away and I can restart the program as
usual.

Is the problem maybe that I'm both sending and receiving out of the same
UDPClient object? It's like something's getting in the way and blocking
the port and the program throws a fit.

Thanks,

--Jon
j@xxxxxxxxxxxxxxx




.



Relevant Pages

  • Re: Einfacher UDP-Client mit VB.NET
    ... offset, Int32 size, SocketFlags socketFlags, EndPoint& remoteEP) ... Dim receiveBytes As = ReceivingUdpClient.Receive ...
    (microsoft.public.de.german.entwickler.dotnet.vb)
  • Re: Einfacher UDP-Client mit VB.NET
    ... offset, Int32 size, SocketFlags socketFlags, EndPoint& remoteEP) ... Dim receiveBytes As = ReceivingUdpClient.Receive ...
    (microsoft.public.de.german.entwickler.dotnet.vb)