The Windows operating system provides mechanisms for
facilitating communications and data sharing between applications.
Collectively, the activities enabled by these mechanisms are called interprocess communications
(IPC). Some forms of IPC facilitate the division of labor among several
specialized processes. Other forms of IPC facilitate the division of
labor among computers on a network.
Typically, applications can use IPC categorized as clients or servers. A client
is an application or a process that requests a service from some other application or process. A server
is an application or a process that responds to a client request. Many
applications act as both a client and a server, depending on the
situation. For example, a word processing application might act as a
client in requesting a summary table of manufacturing costs from a
spreadsheet application acting as a server. The spreadsheet
application, in turn, might act as a client in requesting the latest
inventory levels from an automated inventory control application.
After you decide that your application would benefit from IPC, you
must decide which of the available IPC methods to use. It is likely
that an application will use several IPC mechanisms. The answers to
these questions determine whether an application can benefit by using
one or more IPC mechanisms.
- Should the application be able to communicate with other
applications running on other computers on a network, or is it
sufficient for the application to communicate only with applications on
the local computer?
- Should the application be able to communicate with applications
running on other computers that may be running under different
operating systems (such as 16-bit Windows or UNIX)?
- Should the user of the application have to choose the other
applications with which the application communicates, or can the
application implicitly find its cooperating partners?
- Should the application communicate with many different applications
in a general way, such as allowing cut-and-paste operations with any
other application, or should its communications requirements be limited
to a restricted set of interactions with specific other applications?
- Is performance a critical aspect of the application? All IPC mechanisms include some amount of overhead.
- Should the application be a GUI application or a console application? Some IPC mechanisms require a GUI application.
The following IPC mechanisms are supported by Windows:
Using the Clipboard for IPC
The clipboard acts as a central depository for data sharing among
applications. When a user performs a cut or copy operation in an
application, the application puts the selected data on the clipboard in
one or more standard or application-defined formats. Any other
application can then retrieve the data from the clipboard, choosing
from the available formats that it understands. The clipboard is a very
loosely coupled exchange medium, where applications need only agree on
the data format. The applications can reside on the same computer or on
different computers on a network.
Key Point:
All applications should
support the clipboard for those data formats that they understand. For
example, a text editor or word processor should at least be able to
produce and accept clipboard data in pure text format. For more
information, see
Clipboard
.
Using COM for IPC
Applications that use OLE manage compound documents
— that
is, documents made up of data from a variety of different applications.
OLE provides services that make it easy for applications to call on
other applications for data editing. For example, a word processor that
uses OLE could embed a graph from a spreadsheet. The user could start
the spreadsheet automatically from within the word processor by
choosing the embedded chart for editing. OLE takes care of starting the
spreadsheet and presenting the graph for editing. When the user quit
the spreadsheet, the graph would be updated in the original word
processor document. The spreadsheet appears to be an extension of the
word processor.
The foundation of OLE is the Component Object Model (COM). A
software component that uses COM can communicate with a wide variety of
other components, even those that have not yet been written. The
components interact as objects and clients. Distributed COM extends the
COM programming model so that it works across a network.
Key Point:
OLE supports compound
documents and enables an application to include embedded or linked data
that, when chosen, automatically starts another application for data
editing. This enables the application to be extended by any other
application that uses OLE. COM objects provide access to an object's
data through one or more sets of related functions, known as
interfaces. For more information, see COM and ActiveX Object Services.
Using Data Copy for IPC
Data copy enables an application to send information to another application using the
WM_COPYDATA
message. This method requires cooperation between the sending
application and the receiving application. The receiving application
must know the format of the information and be able to identify the
sender. The sending application cannot modify the memory referenced by
any pointers.
Key Point:
Data copy can be used to quickly send information to another application using Windows messaging. For more information, see
Data Copy
.
Using DDE for IPC
DDE is a protocol that enables applications to exchange data in a
variety of formats. Applications can use DDE for one-time data
exchanges or for ongoing exchanges in which the applications update one
another as new data becomes available.
The data formats used by DDE are the same as those used by the
clipboard. DDE can be thought of as an extension of the clipboard
mechanism. The clipboard is almost always used for a one-time response
to a user command, such as choosing the Paste command from a menu. DDE
is also usually initiated by a user command, but it often continues to
function without further user interaction. You can also define custom
DDE data formats for special-purpose IPC between applications with more
tightly coupled communications requirements.
DDE exchanges can occur between applications running on the same computer or on different computers on a network.
Using a File Mapping for IPC
File mapping
enables a process to treat the contents of a
file as if they were a block of memory in the process's address space.
The process can use simple pointer operations to examine and modify the
contents of the file. When two or more processes access the same file
mapping, each process receives a pointer to memory in its own address
space that it can use to read or modify the contents of the file. The
processes must use a synchronization object, such as a semaphore, to
prevent data corruption in a multitasking environment.
You can use a special case of file mapping to provide named shared memory
between processes. If you specify the system swapping file when
creating a file-mapping object, the file-mapping object is treated as a
shared memory block. Other processes can access the same block of
memory by opening the same file-mapping object.
File mapping is quite efficient and also provides
operating-system–supported security attributes that can help prevent
unauthorized data corruption. File mapping can be used only between
processes on a local computer; it cannot be used over a network.
Key Point:
File mapping is an
efficient way for two or more processes on the same computer to share
data, but you must provide synchronization between the processes. For
more information, see
File Mapping
and
Synchronization
.
Using a Mailslot for IPC
Mailslots provide one-way communication. Any process that creates a mailslot is a mailslot server
. Other processes, called mailslot clients
,
send messages to the mailslot server by writing a message to its
mailslot. Incoming messages are always appended to the mailslot. The
mailslot saves the messages until the mailslot server has read them. A
process can be both a mailslot server and a mailslot client, so two-way
communication is possible using multiple mailslots.
A mailslot client can send a message to a mailslot on its local
computer, to a mailslot on another computer, or to all mailslots with
the same name on all computers in a specified network domain. Messages
broadcast to all mailslots on a domain can be no longer than 400 bytes,
whereas messages sent to a single mailslot are limited only by the
maximum message size specified by the mailslot server when it created
the mailslot.
Key Point:
Mailslots offer an easy
way for applications to send and receive short messages. They also
provide the ability to broadcast messages across all computers in a
network domain. For more information, see
Mailslots
.
Using Pipes for IPC
There are two types of pipes for two-way communication: anonymous pipes and named pipes. Anonymous pipes
enable related processes to transfer information to each other.
Typically, an anonymous pipe is used for redirecting the standard input
or output of a child process so that it can exchange data with its
parent process. To exchange data in both directions (duplex operation),
you must create two anonymous pipes. The parent process writes data to
one pipe using its write handle, while the child process reads the data
from that pipe using its read handle. Similarly, the child process
writes data to the other pipe and the parent process reads from it.
Anonymous pipes cannot be used over a network, nor can they be used
between unrelated processes.
Named pipes
are used to transfer data between processes
that are not related processes and between processes on different
computers. Typically, a named-pipe server process creates a named pipe
with a well-known name or a name that is to be communicated to its
clients. A named-pipe client process that knows the name of the pipe
can open its other end, subject to access restrictions specified by
named-pipe server process. After both the server and client have
connected to the pipe, they can exchange data by performing read and
write operations on the pipe.
Key Point:
Anonymous pipes provide
an efficient way to redirect standard input or output to child
processes on the same computer. Named pipes provide a simple
programming interface for transferring data between two processes,
whether they reside on the same computer or over a network. For more
information, see
Pipes
.
Using RPC for IPC
RPC enables applications to call functions remotely. Therefore, RPC
makes IPC as easy as calling a function. RPC operates between processes
on a single computer or on different computers on a network.
The RPC provided by Windows is compliant with the Open Software
Foundation (OSF) Distributed Computing Environment (DCE). This means
that applications that use RPC are able to communicate with
applications running with other operating systems that support DCE. RPC
automatically supports data conversion to account for different
hardware architectures and for byte-ordering between dissimilar
environments.
RPC clients and servers are tightly coupled but still maintain high
performance. The system makes extensive use of RPC to facilitate a
client/server relationship between different parts of the operating
system.
Key Point:
RPC is a function-level
interface, with support for automatic data conversion and for
communications with other operating systems. Using RPC, you can create
high-performance, tightly coupled distributed applications. For more
information, see
Microsoft RPC Components
.
Using Windows Sockets for IPC
Windows Sockets is an protocol-independent interface. It takes
advantage of the communication capabilities of the underlying
protocols. In Windows Sockets 2, a socket handle can optionally be used
as a file handle with the standard file I/O functions.
Windows Sockets are based on the sockets first popularized by
Berkeley Software Distribution (BSD). An application that uses Windows
Sockets can communicate with other socket implementation on other types
of systems. However, not all transport service providers support all
available options.
Key Point:
Windows Sockets is a
protocol-independent interface capable of supporting current and
emerging networking capabilities. For more information, see
Windows Sockets 2
.
分享到:
相关推荐
《Linux系统中的进程间通信》是由Prentice Hall PTR出版的一部专著,全面深入地探讨了在Linux操作系统中实现进程间通信(IPC)的各种技术和方法。进程间通信是多进程应用程序协同工作的重要机制,它使得不同的进程...
sdk2003 win32 Interprocess Communications sdk2003 win32 Interprocess Communications
《UNIX Network Programming, Volume 2 - Interprocess Communications, Second Edition》是Richard Stevens撰写的一本经典著作,专注于UNIX系统中的进程间通信(IPC)技术。这本书是UNIX网络编程领域的重要参考资料...
UNIX Network Programming, Volume 2, Second Edition: Interprocess Communications, source code && read me && Reported problems UNIX网络编程,第2卷(第2版)IPC,源码,read me, Reported problems
《UNIX Network Programming Volume 2, Interprocess Communications》是著名计算机科学家W. Richard Stevens的经典之作,这本书深入探讨了在UNIX系统中进行进程间通信(IPC)的技术和实践。这本书的第二版详细介绍...
介绍进程间通信的一本不错的书
《Unix Network Programming Vol.2 Interprocess Communication 2nd Edition》是Unix系统编程领域的一部经典著作,由W. Richard Stevens撰写。这本书详细介绍了Unix环境下的进程间通信(IPC,Interprocess ...
unix network programming Volume 2 inter process communications
《Boost.Interprocess 深入解析》 Boost.Interprocess 是 Boost 库中的一个重要组件,它为跨进程的通信和共享内存提供了高效且灵活的解决方案。这个开源库支持多种方式进行进程间通信(IPC),使得不同进程间的数据...
Unix Network Programming volume2 Interprocess Communications 英文第二版 非图片 感谢网友 iyangjian 提供 不敢独享!
### Boost.Interprocess介绍 #### 一、概述 Boost.Interprocess 是一个强大的库,它简化了进程间通信(IPC)及同步机制的使用,并提供了一系列广泛的工具。这些工具可以帮助开发人员在进程之间有效地共享数据和...
UNIX Network Programming, Volume 2 - Interprocess Communications, Second Edition ...
原书名: UNIX Network Programming, Volume 2: Interprocess Communications (2nd Edition) 原出版社: Prentice Hall 作者: (美)W. Richard Stevens [作译者介绍] 丛书名: 图灵程序设计丛书 操作系统 出版社...
原书名: UNIX Network Programming, Volume 2: Interprocess Communications (2nd Edition) 原出版社: Prentice Hall 作者: (美)W. Richard Stevens
### 4.4 BSD进程间通信教程简介 #### 摘要 伯克利 UNIX 4.4 BSD 版本提供了多种进程间通信(IPC)的选择。为了帮助程序员开发由协同进程组成的程序,本文档讨论了不同的 IPC 选项,并通过一系列示例程序展示了这些...
经典网络编程作品——Unix Network Programming 包括第1卷、第2卷的中...Unix Network Programming - vol2 ed2 Interprocess Communications.pdf UNIX网络编程第1卷:套接口API.pdf UNIX网络编程第2卷:进程间通信.pdf
破解版 Create Client/Server applications with powerful InterProcess Communication: Let your Applications cooperate Send and receive Messages, Strings, Stringlists, Arrays, Records and Components ...
在现代操作系统中,进程间的通信(Interprocess Communication, IPC)是至关重要的,它允许不同的进程共享数据、协调工作,从而实现复杂的应用程序。本课件主要涵盖了2.3章节中的IPC概念,包括了一些经典的问题和...