How do I run the demo clients and servers on different hosts?

By default, the demo programs that ship with Ice assume that you will run client and server on the same host. This behavior is controlled by two configuration files, config.client and config.server. For example, here is the relevant line for the server configuration of the hello demo:

Hello.Endpoints=tcp -p 10000:udp -p 10000:ssl -p 10001

This property configures the object adapter endpoints of the object adapter named Hello. The adapter will listen for incoming requests on port 10000 for UDP and TCP, and on port 10001 for SSL. Because this configuration does not use the -h option to explicitly specify an interface, it will use the value of the Ice.Default.Host property and if this property is not set, the server will bind itself to all the network interfaces on the machine.

The corresponding entry for client looks like this:

Hello.Proxy=hello:tcp -p 10000:udp -p 10000:ssl -p 10001

This property defines a stringified proxy that is used by the client to make an invocation. Because the proxy endpoints don't use the -h option to explicitly specify a hostname, the client will use the value of the Ice.Default.Host property. If this property is not set, the client will try to connect to localhost.

If you want to run client and server on different machines, you need to modify the configuration of the client to specify the server's machine. For example, if the server runs on host www.zeroc.com, you can modify the client configuration to specify that machine:

Hello.Proxy=hello:tcp -h www.zeroc.com -p 10000:udp -h www.zeroc.com -p 10000:ssl -h www.zeroc.com -p 10001

This configuration assumes that the DNS for the client can correctly resolve the domain name www.zeroc.com; if that is not the case, you can also use an IP address instead of a domain name.

Because you can configure a separate endpoint for each protocol, you can also create more complex configurations. For example, for a machine with separate interfaces for an external network and an internal network, you could use a server configuration as follows:

Hello.Endpoints=tcp -h internal.zeroc.com -p 10000:udp -h internal.zeroc.com -p 7859:ssl -h external.zeroc.com -p 10001

With this endpoint specification, the server will accept TCP and UDP requests only on the internal interface, at ports 10000 and 7859, respectively, and will accept SSL requests only on the external interface, at port 10001.

Regardless of what configuration you use, if a client cannot reach the server, the first thing to do is to run both client and server with --Ice.Trace.Network=2 and check that the endpoint that the client tries to connect to matches the endpoint at which the server listens. If not, the fault is inevitably in the endpoint configuration of either client or server (or both): the configurations must match for the client to be able to reach the server.

Instead of configuring endpoints manually, you can also let IceGrid take care of port allocation for you.

See Also