So I have an application which has a .NET API available. Their API library communicates with their main application through .NET remoting calls. In order to use the API, the application must be up and running already.
So, I have an instance where I need to programmatically start the application and then instantiate one of the API objects, which attempts to open an IPC remoting channel to the main app. The problem is, after I start the process, there are a few seconds between startup and when the application registers the channel. If I try to instantiate an API object before the channel is registered, it biffs out.
It doesn't help that I know very little about .NET remoting.
How do I determine from MY application which uses their API if THEIR application has registered the channel for communication so I know it's okay to instantiate their API object?
Try this:
using System.Net.NetworkInformation;
using System.Net;
private static bool IsPortAvailable(int port)
{
IPGlobalProperties globalProperties = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] activeListeners = globalProperties.GetActiveTcpListeners();
if (activeListeners.Any(conn => conn.Port == port))
{
return true;
}
return false;
}
Pass in the port and you should get a value indicating whether there is a listener on that port.Hope this helps
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With