Charles Bretana
Charles Bretana

Reputation: 146499

Open tcp remoting channel on specific port

I want to open a tcp port for .Net Remoting callbacks in an application that will run on a terminal server, where multiple concurrent users will be executing and running the app and each must be able to see the incoming callback event messages. Currently, when I attempt to open the port and register the channel in the app, I am using the following:

    private static void RegisterCallBackChannel(int callBackPort)
    {
        var clientProvider = new BinaryClientFormatterSinkProvider();
        var serverProvider = new BinaryServerFormatterSinkProvider 
                {TypeFilterLevel = TypeFilterLevel.Full};

        IDictionary props = new Hashtable();
        var chanNm = string.Format("CallBackChanPort:{0}", callBackPort);
        props["port"] = callBackPort;
        props["name"] = chanNm;
        props["typeFilterLevel"] = TypeFilterLevel.Full;

        if (ChannelServices.RegisteredChannels.Any(
            chn =>  chn is TcpChannel &&  chn.ChannelName == chanNm))
                return;
        var chan = new TcpChannel(props, clientProvider, serverProvider);
        ChannelServices.RegisterChannel(chan, true);
    }

this works for the first user, but when the second concurrent user starts the app in his user session, the .Net code ChannelServices.RegisteredChannels does not contain the channel opened ny the first user, but of course the line of code

var chan = new TcpChannel(props, clientProvider, serverProvider);   

fails because you cannot open two channels on the same port on the same machine, even if they are in different user sessions.

How do I do this? Even if I could detect if the specific port is already open, can applications in one user sesion see incoming event messages on a channel created from a different user session ??

Upvotes: 2

Views: 1389

Answers (0)

Related Questions