Referrers

Referrers or brokers are so named because they are responsible for referring clients to a particular object. In some systems, clients usually don’t know where the target servers run, but they know one important agent, the broker, who can refer them to the appropriate servers. Typically, servers register themselves with a broker when they start up. When a client asks the broker for a particular service, the broker will return the registered server that supports the requested service. Brokers can do much more than this; for example, load balancing is something that can be done by the broker to equally distribute server loads. However, referrals are enough to illustrate the importance of the OBJREF.

Therefore, in our exercise, we’ll create a ChatBroker to refer a ChatClient to an appropriate ChatServer. As alluded to earlier, a ChatServer uses the IRegisterChatServer interface to register itself by passing its ISendMessage interface pointer to the ChatBroker. The ChatBroker keeps a list of ISendMessage interface pointers exposed by ChatServers, each representing a particular discussion topic. From this discussion list, a ChatClient may choose to join one of these discussions. Once the choice is made, the ChatBroker passes the ISendMessage interface pointer to the ChatClient. The ChatClient uses the ISendMessage to send chat messages to the ChatServer, even though it has no idea where in cyberspace the ChatServer runs.

Creating the ChatBroker Component

Let’s start off by creating ...

Get Learning DCOM now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.