Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I tell if another app has registered an IPC Remoting channel?

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?

like image 974
snicker Avatar asked Nov 05 '22 19:11

snicker


1 Answers

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

like image 194
Abhijeet Patel Avatar answered Nov 15 '22 06:11

Abhijeet Patel