0

I have two apps on two computers. These apps are communicating by .NET Remoting. First app acts as server for access to database, second app acts as client and writes that data to another database.

When my client calls some method on my remote object on server, I get following error:

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 192.168.200.60:31621

Well, that's nice, but I don't know anything about IP address 192.168.200.60, I was connecting to 172.XXX.XXX.216. It seems that there are two network connections and it's somehow not good for remoting.

ipcongif on my server look like that:

enter image description here

Exactly the same solution works on another 3 computers with Windows 2000, Windows XP and Windows 7. Server is developed in .NET Framework 2.0.

Client and server have common DLL library with two interfaces ICAOFactory and ICAO. First I create factory CAOFactory, which has method CreateCAO, which returns CAO object. When I call some method oh that ICAO object, it fails.

This is how my server app registers remoting object:

TcpChannel channel = new TcpChannel(31621); 
ChannelServices.RegisterChannel(channel, false);
RemotingConfiguration.RegisterWellKnownServiceType(typeof(My_Server.CAOFactory), "My_Server", WellKnownObjectMode.Singleton);

This is how my client creates remote object:

My_Share.ICAOFactory srvFactory;
My_Share.ICAO srvCAO;

srvFactory = (My_Share.ICAOFactory)Activator.GetObject(typeof(Foerster_Share.ICAOFactory), "tcp://" + ip + ":" + port + "/My_Server");
srvCAO = srvFactory.CreateCAO(); // no problem
srvCAO.Init(dateTime); // problem

This is my CAOFactory object:

public class CAOFactory : MarshalByRefObject, ICAOFactory
{
    public ICAO CreateCAO()
    {
        ICAO CAOObj = new CAO();
        return CAOObj;
    }

    public void GetClientCount(out long clientCountSum, out long clientCountMax, out long clientCountActive)
    {
        clientCountSum = 0;
        clientCountMax = 0;
        clientCountActive = 0;
        return;
    }

    public override object InitializeLifetimeService()
    {
        return null;
    }
}

This is my CAO object:

public class CAO : MarshalByRefObject, ICAO
{
    public void Ping()
    {
        return;
    }

    DateTime dtInit;

    public void Init(DateTime dt)
    {
        dtInit = dt;
    }

    // + some other methods
}

Any help greatly appreciated!

Gabriel
  • 377
  • 1
  • 3
  • 15
  • 1
    How about posting the code that is failing? –  Jun 26 '17 at 10:30
  • so your primary machine has 2 Ips you can check which IPs are listening on that port from the command line have you done this? im guessing that the client is on the 168 network and your "server" machine has 2 networks and assigned to the "first" ip it found which was the 172 network - if you dont know much about networks nows a great time to learn some basics – BugFinder Jun 26 '17 at 10:37
  • @BugFinder Yes, you're right, I am the beginner in networks. I didn't do the check from the command line. How can I do that? – Gabriel Jun 26 '17 at 10:45
  • checking that is an OS level thing not a network thing.. but .. try netstat -an look for your port... it shows all ports you need to look for yours – BugFinder Jun 26 '17 at 10:46
  • it show what I want TCP 172.XXX.XXX.216:31621 172.XXX.XXX.66:2532 ESTABLISHED – Gabriel Jun 26 '17 at 10:53
  • @ojf I added my code to the question. – Gabriel Jun 26 '17 at 12:45

2 Answers2

1

What version of .NET are you targeting?

I think you need to use the bindTo property of the TcpChannel class https://msdn.microsoft.com/en-us/library/bb187434(v=vs.85).aspx to tell your server to bind to the correct NIC. This is probably most easily done in the configuration. Does your server project have an app.config? If not add one then add a section like this to it (this is copy/pasted from this question .Net Remoting: Indicate which local interface to use to connect to one server)

<configuration>
    <system.runtime.remoting>
        <application>
            <channels>
                <channel ref="tcp" port="0" bindTo="172.xxx.xxx.xxx" />
            </channels>
        </application>
    </system.runtime.remoting>
</configuration>

This will tell the server to bind to the specific IP address.

1

Reordering network connection priority helped in my case.

http://ecross.mvps.org/howto/change-network-connection-priority-in-windows-10.htm

  1. Press the Windows Key + X and select Network Connections from the menu.
  2. Press the ALT key, click Advanced and then Advanced Settings.
  3. Select the network connection and click the arrows to give priority to the network connection.

enter image description here

  1. Click Ok when you are done organizing the priority of the network connection. The computer will now follow an order when connections are available.
Gabriel
  • 377
  • 1
  • 3
  • 15