2

For a project we're working on, we're using .NET remoting to communicate between the server and client. So far we've been testing it on the same machine and its worked, using localhost and an arbitrary port number. However, when testing between two machines on the same network, using, the main component works, but a proxy object fails.

We're using configuration files to set the server name and port, like this:

<setting name="ServerName" serializeAs="String">
    <value>192.168.1.141</value>
</setting>
<setting name="Port" serializeAs="String">
    <value>9932</value>
</setting>

The client sets up the remoting object as follows:

_port = global::ConsoleClient.Properties.Settings.Default.Port;
_servername = global::ConsoleClient.Properties.Settings.Default.ServerName;

string url = "tcp://" + _servername + ":" + _port + "/Lobby";

try
{
    ChannelServices.RegisterChannel(new TcpClientChannel(), false);
    Lobby lobby = (Lobby)Activator.GetObject(
        typeof(Lobby), url);
}
catch (Exception e)
{
}

This works fine and we are able to call methods on the lobby object. However, later on in the code, we return another object, table as follows:

table_proxy = lobby_proxy.joinTable(userID, i);

where lobby_proxy is the same lobby object in the prior code. The server is configured in the following manner:

_port = global::Server.Properties.Settings.Default.Port;
_lobby = new Lobby(_db);

try
{
    TcpServerChannel channel = new TcpServerChannel(_port);
    ChannelServices.RegisterChannel(channel, false);
    RemotingConfiguration.RegisterWellKnownServiceType(typeof(Lobby),
            "Lobby", WellKnownObjectMode.Singleton);
    RemotingServices.Marshal((_lobby), "Lobby");
    System.Console.WriteLine("Press Any Key");
}
catch (Exception e)
{
    System.Console.WriteLine(e);
}

This works fine when run on the same machine, but throws the following error when run on separate machines:

System.Net.Sockets.SocketException (0x80004005): A socket operation was attempte
d to an unreachable network 169.254.171.86:9932
   Exit
Server stack trace:
   at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddre
ss socketAddress)
   at System.Net.Sockets.Socket.Connect(EndPoint remoteEP)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket(EndPoint
 ipEndPoint)
   at System.Runtime.Remoting.Channels.RemoteConnection.CreateNewSocket()
   at System.Runtime.Remoting.Channels.RemoteConnection.GetSocket()
   at System.Runtime.Remoting.Channels.SocketCache.GetSocket(String machinePortA
ndSid, Boolean openNew)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.SendRequestWit
hRetry(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream)
   at System.Runtime.Remoting.Channels.Tcp.TcpClientTransportSink.ProcessMessage
(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITranspor
tHeaders& responseHeaders, Stream& responseStream)
   at System.Runtime.Remoting.Channels.BinaryClientFormatterSink.SyncProcessMess
age(IMessage msg)

Exception rethrown at [0]:
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage req
Msg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgDa
ta, Int32 type)
   at JackOfTrades.Common.Table.GetTableData(Boolean full)

Looking at the top, there is an IP address that I do not recognize, it's neither on the network nor the IP of the router.

Any thoughts on whats wrong? Help would be greatly appreciated!

achinda99
  • 5,020
  • 4
  • 34
  • 42
  • The IP: `169.254.171.86` looks like an windows autoconfigured IP address, which usually results from a network adapter (like a secondary adapter) that isn't connected to a network. Is there somewhere in the code where you are attempting to discover the IP address of the local machine and possibly not being specific as to which adapter you're getting the address for? – CodingGorilla Nov 09 '10 at 14:33

2 Answers2

4

You need to setup TcpServerChannel with following parameter:

bindTo
A string that specifies the IP address of the network interface card (NIC) to which the server channel should bind. The default value is System.Net.IPAddress.Any.

http://msdn.microsoft.com/en-us/library/bb397831.aspx

UPDATED:

IDictionary properties = new Hashtable();
properties["port"] = 9932;
properties["bindTo"] = "192.168.1.141";
TcpServerChannel channel = new TcpServerChannel(properties, null);
ChannelServices.RegisterChannel(channel,  false);
QrystaL
  • 4,886
  • 2
  • 24
  • 28
  • I was looking into this and I can't seem to figure out how to use bindTo within TcpServerChannel. Any resources that show how? It doesn't seem to be an available option. – achinda99 Nov 09 '10 at 15:22
1

A 168.254.x.x address is usually seen when a network adapter cannot get a DHCP address.

I would check to make sure that the machine you are running this code on has a valid IP address.

Moose
  • 5,354
  • 3
  • 33
  • 46
  • Well, I'm testing this on a home network, where the router is providing 192.168.1.x IPs. And the correct IP addresses are being used in the configuration files to create the connection. I'm not sure where 168.254.x.x is being pulled from. – achinda99 Nov 09 '10 at 15:04