Friday, November 21, 2008

Interactions between client and server


In COM, the client program drives everything. Servers are entirely passive, only responding to requests. This means COM servers behave in a

synchronous manner toward individual method calls from the client.

l The client program starts the server.

l The client requests COM objects and interfaces.

l The client originates all method calls to the server.

l The client releases server interfaces, allowing the server to shut down.

This distinction is important. There are ways to simulate calls going from server to client, but they are difficult to implement and fairly complex

(They are called callbacks). In general, the server does nothing without a client request.

Here is a typical interaction between a COM client and server:


Client Request Server Response

Requests access to a specific COM

interface, specifying the COM class and

interface (by GUID)

l Starts the server (if required). If it is an In-Process server, the DLL will be loaded.

Executable servers will be run by the SCM.

l Creates the requested COM object.

l Creates an interface to the COM object.

l Increments the reference count of active interfaces.

l Returns the interface to the client.

Calls a method of the interface. Executes the method on a COM object.

Release the interface

l Decrements the interfaces reference count.

l If the reference count is zero, it may delete the COM object.

l If there are no more active connections, shut down the server. Some servers do not shut

themselves down.

If you're going to understand COM, you must take a client-centric approach.


Summary

We've tried to look at COM from several points of view. C++ is the native language of COM, but it's important to see beyond the similarities.

COM has many analogues in C++, but it has important differences. COM offers a whole new way of communicating between clients and

servers.

The interface is one of the most important COM concepts. All COM interactions go through interfaces, and they shape that interaction. Because

interfaces don't have a direct C++ counterpart, they are sometimes difficult for people to grasp. We've also introduced the concept of the

GUID. GUID's are ubiquitous in COM, and offer a great way to identify entities on a large network.

COM servers are merely the vehicles for delivering COM components. Everything is focused on the delivery of COM components to a client

application. In the following chapters, we'll create a simple client and server application to demonstrate these concepts.

0 comments: