How do I run client and server on different hosts?

When a server creates an object adapter, it specifies transport endpoints for the adapter. For example:

createObjectAdapterWithEndpoints("foo", "default -p 10000")

This call instructs the Ice run time to create an adapter named "foo" that, once activated, accepts incoming connections on port 10000 using the default protocol (TCP, SSL, or UDP), as configured by the Ice.Default.Protocol property. (If the property is not set, the default protocol is TCP.)

When a client uses a proxy to invoke an operation on an Ice object, the client-side run time attempts to contact the server for the object at the endpoint that is specified for the proxy. Clients can create a proxy using the stringToProxy helper function, which expects a stringified proxy that specifies:

  • the identity of the target object
  • the host on which the server runs
  • the port on which the server listens for incoming requests

For an invocation from the client to reach the server, the host must be the server's host, and the port number must match the port number that was used for the server's object adapter. For example, if we assume that the object's identity is "Fred", and that the server runs on the host s1.zeroc.com, the client would use

stringToProxy("Fred:tcp -h s1.zeroc.com -p 10000")

In general, the string to define a proxy has the form <identity>:<endpoints>. The –h option specifies the host, either as a domain name or as an IP address, and the –p option specifies the server’s port. You can specify several endpoints, in which case you must separate the endpoints must from each other with a colon.

If you try to run client and server on different hosts, and find that the client cannot connect (the first remote call will usually raise a ConnectionRefusedException in this case), you should run both server and client with the --Ice.Trace.Network=2 option. This will allow you to see at what IP address and port number the server listens for incoming requests, and it will allow you to see where the client attempts to contact the server.

Proxies that contain the endpoint of the server, as in the preceding example, are known as direct proxies. Ice also supports indirect proxies, which do not contain endpoint information. The client-side run time transparently resolves such proxies to an actual endpoint with the help of IceGrid.

See Also