---
title: "Routers"
url: https://docs.zeroc.com/ice/3.8/runtime/invocation/routers
language: java
docs_index: https://docs.zeroc.com/llms.txt
---

> For an index of every page, see [llms.txt](https://docs.zeroc.com/llms.txt).

# Routers

Programming language: Java. Other languages: [C++](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/cpp.md), [C#](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/csharp.md), [JavaScript](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/js.md), [MATLAB](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/matlab.md), [PHP](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/php.md), [Python](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/python.md), [Ruby](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/ruby.md), [Swift](https://docs.zeroc.com/ice/3.8/runtime/invocation/routers/swift.md).

A *router* is an Ice object that forwards requests between clients and servers. On this page, the client is the application that connects to the router, and the server is the application the router forwards to, whichever of them sends a request. A proxy configured to use a router is a *routed proxy*: Ice sends its requests to the router, which forwards them to the target server. Ice connects to the router rather than to the endpoints of the routed proxy, and typically opens a single connection to a router for all the routed proxies that use it.

A router implements the `Ice::Router` interface. Ice includes two routers:

- [Glacier2](https://docs.zeroc.com/ice/3.8/services/glacier2.md) forwards the requests of authenticated clients to servers on another network, typically behind a firewall, and forwards callbacks to these clients over their existing connections. It finds the target of each request by its identity, so the objects that a client reaches through Glacier2 need [unique identities](https://docs.zeroc.com/ice/3.8/runtime/object-identity/java.md).
- [IceBridge](https://docs.zeroc.com/ice/3.8/services/icebridge.md) forwards requests to a single target server that the clients cannot reach directly, for example because they do not support its transport.

## Creating Routed Proxies

A communicator can have a default router. Every proxy this communicator creates, from a string, from a property, or by unmarshaling a proxy returned by an operation, is a routed proxy that uses this router. The [Ice.Default.Router](https://docs.zeroc.com/ice/3.8/property-reference/ice-default-properties/java.md#ice.default.router) property sets the default router; the value is a proxy for the router:

```config
Ice.Default.Router=Glacier2/router:tcp -h routerhost -p 4063
```

`setDefaultRouter` on the communicator sets the default router of the proxies created afterwards, and `getDefaultRouter` returns it. The default router does not apply to object adapters.

The `ice_router` proxy factory method returns a routed proxy:

```java
var router = RouterPrx.createProxy(...);
var greeter = GreeterPrx.createProxy(...); // normal proxy
var routedGreeter = greeter.ice_router(router);
```

The [Router](https://docs.zeroc.com/ice/3.8/property-reference/proxy-properties/java.md#name.router) proxy property sets the router of the proxy that `propertyToProxy` creates:

```config
MyProxy.Router=Glacier2/router:tcp -h routerhost -p 4063
```

## Callbacks Through a Router

A client that receives callbacks through a router creates an object adapter associated with this router, with the [*adapter*.Router](https://docs.zeroc.com/ice/3.8/property-reference/object-adapter-properties/java.md#adapter.router) property or by calling `createObjectAdapterWithRouter`. A communicator can have only one object adapter associated with a given router.

This object adapter does not accept incoming connections, and you must not set its `Endpoints` property: it receives requests over the [bidirectional connection](https://docs.zeroc.com/ice/3.8/runtime/connection-management/bidirectional-connections/java.md) between the client and the router. The proxies it creates carry the endpoints of the router's server proxy, returned by [`getServerProxy`](https://code.zeroc.com/ice/3.8/api/java/com.zeroc.ice/com/zeroc/Ice/RouterPrx.html#getServerProxy()): a server that makes an invocation with such a proxy sends the request to the router, which forwards it to the client.

See [Callbacks Through Glacier2](https://docs.zeroc.com/ice/3.8/services/glacier2/callbacks-through-glacier2/java.md) for an example.

## See Also

- [Glacier2](https://docs.zeroc.com/ice/3.8/services/glacier2.md)
- [IceBridge](https://docs.zeroc.com/ice/3.8/services/icebridge.md)
