views:

638

answers:

3

I've got a remoting server and client built. The server is set up as such:

BinaryServerFormatterSinkProvider serverProv = 
    new BinaryServerFormatterSinkProvider();
serverProv.TypeFilterLevel = TypeFilterLevel.Full;
BinaryClientFormatterSinkProvider clientProv = 
    new BinaryClientFormatterSinkProvider();

IDictionary props = new Hashtable();
props["port"] = port;

TcpChannel channel = new TcpChannel( props, clientProv, serverProv );

ChannelServices.RegisterChannel( channel, false );

RemotingConfiguration.RegisterWellKnownServiceType( typeof( Controller ),
    "Controller", WellKnownObjectMode.Singleton );

The client is set up as such:

ChannelServices.RegisterChannel( new TcpChannel( 0 ), false );
m_Controller = (Controller)RemotingServices.Connect( typeof( Controller ), 
      "tcp://" + ip + ":2594/Controller" );

When I try to connect to the server from the same computer with the IP specified as 'localhost,' it connects fine. However, when I try to connect from a remote computer, not on the LAN, given the server's IP address, I receive the following exception on the client after a long wait:

A connection attempt failed because the connected party did not properly
respond after a period of time

How can I resolve this? I'm sure it's a configuration problem because the ports are forwarded properly on the server and there is no firewall active.

Thanks

A: 

This sounds like the server didn't activate. When using localhost, how did you start the server? Did you do the same using the remote IP address?

John Saunders
A: 

From a command prompt (cmd.exe), run netstat -a on the server-side and look at just the LISTENING lines. There should be one showing the port your server is running on as the number after the colon in the Local Address column:

>netstat -a
...
Proto  Local Address          Foreign Address        State
TCP    0.0.0.0:135            Blah:0                LISTENING
TCP    127.0.0.1:136          Blah:0                LISTENING

If the Local Address is shown as 127.0.0.1 it means your server application is listening only on the loopback adapter. This adapter allows only connections from the local machine back to itself (hence the name) so remote connections to such ports will not be accepted. Note that the name 'localhost' is a name for 127.0.0.1, so if you have specified that anywhere this could be the explanation. (136 in the above example shows a listening loopback socket.)

If the Local Address is shown as 0.0.0.0 it means your server application is listening on all adapters and (providing you have a network adapter which I will assume you have) remote connections will be accepted. (135 in the above example.)

The final case if the Local Address is another IP address then your server application is listening on a particular network adapter. If you have multiple adapters it could be it is listening on the wrong one.

Now, having said all this, I have just a small application with the code you posted and it appears the default is to listen on 0.0.0.0 (all adapters) so I would be surprised if you see something else. If you do see 0.0.0.0, then my next port of call would be to look at firewalls on both the client and server, both local and corporate if you are in an organisation.

If you have console access to the remote machine then you could try telneting back to the local machine on that port to see if it indeed listening for connections. I would also be tempted to substitute a simple TCP listener, such as Netcat, on the server to see if the problem lays with your application or in the infrastructure.

Paul Ruane
I've checked all this and it looks fine. Clients can telnet in on the port. It's got to be a remoting configuration problem, but I can't seem to spot it.
A: 

This question is a month old, but none the less:

Sniffing the traffic on the server (and preferably, on the client as well) should give you more insight as to what's going on.

For the job I recommend Packetyzer, a very friendly packet sniffer for Windows.

Yariv