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

Detecting loss of network

I am using the following code to monitor a socket port. The code normally
works fine unless a network connection is lost. Since both ends of the
conversation on the same computer (normally) this causes a problem because
they can no longer connect. On my system if the network is reconnected the
two system can start communicating again but on other systems I am told they
can not.

One program is a service and the other is the user interface which is why I
am doing this.

So the questions:

1) Is there a way of handling this so a loss of the network connection does
not drop the connect when both programs are on the same system?

2) Is there anyway for the listener to determine that the network connect
has been lost?

3) In the latest version of .NET have them implemented memory pipes yet?

Regards,
John
CODE:

IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
foreach(IPAddress ipAddress in ipHostInfo.AddressList)
{
try
{
int ConnectionPort = (int)Utils.MiscFuns.ReadRegData(false, "Socket",
"Monitor Port", 12000);
int MaxThrds = (int)Utils.MiscFuns.ReadRegData(false, "Socket", "Max
Threads", 5);

IPEndPoint localEndPoint = new IPEndPoint(ipAddress, ConnectionPort);
if (localEndPoint.AddressFamily == AddressFamily.InterNetwork)
{
Socket listener = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
listener.Bind(localEndPoint);
listener.Listen(MaxThrds);
this.ListenerList.Add(listener);
}
}
catch(System.Threading.ThreadAbortException abEx)
{
throw abEx;
}
catch(Exception ex)
{
this.onException(ex);
System.Diagnostics.Debug.WriteLine("Monitor Thread (IPAddress)" +
ex.Message);
}
}
while(this.IsRun)
{
try
{
ArrayList tmpPortList = new ArrayList();
foreach(object o in this.ListenerList)
tmpPortList.Add(o);

if(tmpPortList.Count > 0)
{
Socket.Select(tmpPortList, null, null, 1000);
foreach(object o in tmpPortList)
{
Socket s = ((Socket)o).Accept();
/// start thread to do something
}
}
}
catch(System.Threading.ThreadAbortException abEx)
{
throw abEx;
}
catch(Exception ex)
{
this.onException(ex);
System.Diagnostics.Debug.WriteLine("Monitor Thread (IPAddress2)" +
ex.Message);
}
}
Mar 29 '06 #1
0 1339

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

Similar topics

4
by: Michael Albanese | last post by:
I am trying to build a user control that will allow a user to select a date from a calendar. I have to code that will run on the calendar's SelectionChanged event, but i am at a loss to return the...
3
by: Sandeep Arya | last post by:
Thanks linuxfreak and sybren for positive comments My application will be running on Linux. How to send ICMP ECHO as broadcast packets. I do not know this. Please tell me how to? Sybren.....
0
by: sid | last post by:
Data loss in Access-97 from VB 6.0 I have encountered Random data loss in our access database. Sometimes the users call in saying that the records entered by them are lost. The users, use our VB...
2
by: ASP.Confused | last post by:
How would I go about detecting a memory leak? My web hosting provider has our site set up to only have a root "bin" folder for .NET apps, and I would like to be able to watch how much memory is...
4
by: Chris | last post by:
When a request comes into a page on my ASP.net site and a session is not found, I want to detect whether the request is an initial request or if the user did have a session going that has now been...
3
by: Martin B | last post by:
Hallo! I'm working with C# .NET 2.0, implementing Client/Server Applications which are connecting via Network to SQL-Server or Oracle Databases. To stay independent from the underlaying Database...
2
by: =?Utf-8?B?TVNXaW5kb3dzUHJvZg==?= | last post by:
hi, We are trying to figure out a way of detecting any incoming http request, to our ASP.NET 2.0 application, if it is coming from our internal network (intranet) vs from outside of our...
1
by: rajeshrocks2006 | last post by:
Hi, i need help in detecting usb port in a network and have to provide authentication for the USB port for the system security purposes...plzz help me....
3
by: limperger | last post by:
Hello! This is quite important. We have an Access file shared in a network. Every user has its front-end copy that is linked to a back-end copy. This database has an autonumber field to count...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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...
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
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,...

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.