473,219 Members | 1,653 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,219 software developers and data experts.

UDPListener: System.Net.Sockets.SocketException

J C
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@fourtentech.com
Apr 3 '06 #1
3 11538
J C
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@fourtentech.com> wrote in message
news:OG**************@TK2MSFTNGP09.phx.gbl...
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@fourtentech.com

Apr 3 '06 #2
Hello, J!

Can you post the code sample where you perform network I/O?

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

Do you use UDPClient.Connect(...) method?
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com
Apr 3 '06 #3
J C
Sure... the general idea is:

namespace dnsone_c {
class Program {
static void Main(string[] args) {
CoolUDP myCoolUDP = new CoolUDP();
myCoolUDP.Receive();
}
}

class CoolUDP {
private IPEndPoint myEndPoint = new IPEndPoint(IPAddress.Any, 53);
private IPEndPoint herEndPoint = new IPEndPoint(IPAddress.Any, 0);

public void Receive() {
UdpClient myListener = new UdpClient(myEndPoint);
byte[] herDNSQuery;
string herDNSQueryText;

while (true) {
try {
herDNSQuery = myListener.Receive(ref herEndPoint);
} catch {
Console.WriteLine("Big error (1).");
continue;
}

if( //i like the packet )
//generate a response in byte[] myDNSResponse

try {
myListener.Send(myDNSResponse, myDNSResponse.Length,
herEndPoint);
}
catch {
Console.WriteLine("Big error (2).");
continue;
}
}
}
}
}
}

--Jon

"Vadym Stetsyak" <va*****@ukr.net> wrote in message
news:ed**************@tk2msftngp13.phx.gbl...
Hello, J!

Can you post the code sample where you perform network I/O?

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

Do you use UDPClient.Connect(...) method?
--
Regards, Vadym Stetsyak
www: http://vadmyst.blogspot.com

Apr 3 '06 #4

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

Similar topics

4
by: Sagaert Johan | last post by:
i get this error if i write this : using System.Net.Sockets; .... .... TcpClient tcp; tcp=new TcpClient();
0
by: Tim Wagaman | last post by:
I an having issuses with a loop I am running to keep checking for messages coming across our line. The goal: Listen for messages on port 5001 and print the messages into a text file. The port...
1
by: Eric Sheu | last post by:
Greetings, I have been searching the web like mad for a solution to my SMTP problem. I am using Windows Server 2003 and ASP.NET 2.0 w/ C# to send out e-mails from a web site I have created to...
0
by: oferns | last post by:
Hi, apologies for the cluncky title.... Using WinXpSP2 & VS2005 Express editions..... I am writing an asynchronous socket client and I am getting a SocketException error on creating the...
7
by: Lee | last post by:
Hey all, I'm using the following code to send stuff accross the network, appologies for it being in full, but I've really no idea exactly where this error is occuring. =======network...
2
by: Steve Lowe | last post by:
Hi, I have a VB.Net 2003 program that uses Indy to check if there are any messages waiting on a POP mail server. The program has been running fine for a few months, but last week after...
4
by: sd1978 | last post by:
Hi, I have placed a webservice in the webserver. When I access it from a webpage, default.aspx on a click of a button i get the following error: No connection could be made because the target...
5
by: PJ6 | last post by:
I can't figure this out. I have several references to style sheets and javascript files in my page header, the contents of which are served dynamically by my httphandler that serves *.res requests....
1
by: larspeter | last post by:
Hi all. I have a problem with TcpClient ... I am conneting to a server with TcpClient and returning the answer through a webservice. It actully all works fine. BUT if I make a lot of...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

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.