473,695 Members | 2,405 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

UDPListener: System.Net.Sock ets.SocketExcep tion

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.Sock ets.SocketExcep tion: An existing
connection
was forcibly closed by the remote host
at System.Net.Sock ets.Socket.Rece iveFrom(Byte[] buffer, Int32 offset,
Int32 s
ize, SocketFlags socketFlags, EndPoint& remoteEP)
at System.Net.Sock ets.UdpClient.R eceive(IPEndPoi nt& remoteEP)
at dnsone_c.CoolUD P.Receive()
at dnsone_c.Progra m.Main(String[] args)

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

Unhandled Exception: System.Net.Sock ets.SocketExcep tion: Only one usage of
each
socket address (protocol/network address/port) is normally permitted
at System.Net.Sock ets.Socket.DoBi nd(EndPoint endPointSnapsho t,
SocketAddress
socketAddress)
at System.Net.Sock ets.Socket.Bind (EndPoint localEP)
at System.Net.Sock ets.UdpClient.. ctor(IPEndPoint localEP)
at dnsone_c.CoolUD P.Receive()
at dnsone_c.Progra m.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.c om
Apr 3 '06 #1
3 11580
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******** ******@TK2MSFTN GP09.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.Sock ets.SocketExcep tion: An existing
connection
was forcibly closed by the remote host
at System.Net.Sock ets.Socket.Rece iveFrom(Byte[] buffer, Int32 offset,
Int32 s
ize, SocketFlags socketFlags, EndPoint& remoteEP)
at System.Net.Sock ets.UdpClient.R eceive(IPEndPoi nt& remoteEP)
at dnsone_c.CoolUD P.Receive()
at dnsone_c.Progra m.Main(String[] args)

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

Unhandled Exception: System.Net.Sock ets.SocketExcep tion: Only one usage of
each
socket address (protocol/network address/port) is normally permitted
at System.Net.Sock ets.Socket.DoBi nd(EndPoint endPointSnapsho t,
SocketAddress
socketAddress)
at System.Net.Sock ets.Socket.Bind (EndPoint localEP)
at System.Net.Sock ets.UdpClient.. ctor(IPEndPoint localEP)
at dnsone_c.CoolUD P.Receive()
at dnsone_c.Progra m.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.c om

Apr 3 '06 #2
Hello, J!

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

J> Unhandled Exception: System.Net.Sock ets.SocketExcep tion: An existing
J> connection
J> was forcibly closed by the remote host
J> at System.Net.Sock ets.Socket.Rece iveFrom(Byte[] buffer, Int32 offset,
J> Int32 s
J> ize, SocketFlags socketFlags, EndPoint& remoteEP)
J> at System.Net.Sock ets.UdpClient.R eceive(IPEndPoi nt& remoteEP)
J> at dnsone_c.CoolUD P.Receive()
J> at dnsone_c.Progra m.Main(String[] args)

Do you use UDPClient.Conne ct(...) 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.Recei ve();
}
}

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

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

while (true) {
try {
herDNSQuery = myListener.Rece ive(ref herEndPoint);
} catch {
Console.WriteLi ne("Big error (1).");
continue;
}

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

try {
myListener.Send (myDNSResponse, myDNSResponse.L ength,
herEndPoint);
}
catch {
Console.WriteLi ne("Big error (2).");
continue;
}
}
}
}
}
}

--Jon

"Vadym Stetsyak" <va*****@ukr.ne t> wrote in message
news:ed******** ******@tk2msftn gp13.phx.gbl...
Hello, J!

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

J> Unhandled Exception: System.Net.Sock ets.SocketExcep tion: An existing
J> connection
J> was forcibly closed by the remote host
J> at System.Net.Sock ets.Socket.Rece iveFrom(Byte[] buffer, Int32
offset,
J> Int32 s
J> ize, SocketFlags socketFlags, EndPoint& remoteEP)
J> at System.Net.Sock ets.UdpClient.R eceive(IPEndPoi nt& remoteEP)
J> at dnsone_c.CoolUD P.Receive()
J> at dnsone_c.Progra m.Main(String[] args)

Do you use UDPClient.Conne ct(...) 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
6852
by: Sagaert Johan | last post by:
i get this error if i write this : using System.Net.Sockets; .... .... TcpClient tcp; tcp=new TcpClient();
0
1533
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 must stay open at all times and only close if no activity for 60 seconds. The problem: If I do a read on a networkstream and the connection is closed
1
8177
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 the members of my organization. I think my problem is incorrectly setting the settings on my server or an authentication problem. Here is the code I have written to send a test message: -----Code Begins: Sensitive Information Replaced by -----...
0
3131
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 socket: + EnableBroadcast 'this.client.EnableBroadcast' threw an exception of type 'System.Net.Sockets.SocketException' bool
7
5602
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 code============ using System; using System.Net; using System.Net.Sockets; using System.Threading;
2
4542
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 Installing a network packet reading program called WireShark my VB.Net program no longer runs and generates the following error : An unhandled exception of type 'System.Net.Sockets.SocketException'
4
5012
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 machine actively refused it Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details:...
5
2629
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. The handler works most of the time, but occasionally the page load hangs on the loading of the last .res reference for a javascript file (Fiddler shows me this), and when I stop the load in the browser, I get this error message: A first chance...
1
4460
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 (re)connection (hitting the submit button) then I start to recieve a an error: IOException:System.IO.IOException: Der kunne ikke læses data fra transportforbindelsen (LPF: could not read data from the transport
0
8586
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9004
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8838
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7683
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6506
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4592
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3025
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2289
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.