Event Sinks

Now that you have the ChatServer component in place, you’ll build the ChatClient component. As shown earlier in Figure 10-2, this component implements a COM object that is an event sink that will receive all messages fired off by the event source object in the ChatServer component. Specifically, as soon as the ChatServer component receives a chat message, it sends the same message back to all connected ChatClients through the client’s event sink object, shown in Figure 10-2 as CoMsgSink. The CoMsgSink object supports a callback interface called IReceiveMessage that the ChatServer component can utilize to make callbacks. Recall that you’ve defined this interface earlier in the last section, but you haven’t implemented it. You’ll do that in this section.

Besides implementing an event sink in this section, you’ll see the special contribution of this chapter in the subsection on Joining and Leaving a Chat Discussion where you contact the ChatBroker to find a ChatServer. You get a handle to the ChatServer via an interface pointer. Remember that this interface pointer is passed from the ChatServer to the ChatBroker to the ChatClient in the form of an OBJREF, and an OBJREF is the key that opens up distributed computing.

Creating the ChatClient Project

Our goal in this section is to develop a client application that looks similar to the one shown in Figure 10-3. So let’s use the MFC AppWizard EXE to create a Dialog base application and name this project ChatClient.

Creating the ...

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.