background preloader

IPC

Facebook Twitter

Inter-Process Communication

Interprocess Communications. 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. After you decide that your application would benefit from IPC, you must decide which of the available IPC methods to use.

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? The following IPC mechanisms are supported by Windows: Using the Clipboard for IPC Using COM for IPC. Pipes. Pipe Functions. Machine Cycle: Pipe Dreams (or: VBScript, Spawned Processes and StdOut/StdErr Capture) I mentioned before that I'm writing a small console utility for Window$ that reads and writes a lot of files. It works nicely on my Debian machine, both when compiled natively and when cross compiled for Window$ and run with Wine. It even works when run in a console window on my wife's PC. So far so good, but I intend to spawn the program from within a VB script, run by the Windows Script Host. So I wrote a little script that (I thought) does exactly that. ' do.vbs - run a command and echo its output' usage: ' cscript do.vbs "command arguments ...

" Sub runCommand(strCommand) Set objScriptExec = WshShell.Exec(strCommand) strStdOut = objScriptExec.StdOut.ReadAll WScript.Echo strStdOut Set objScriptExec = NothingEnd Sub This works nicely with commands like "dir C:" or "ipconfig /all", or any other program that only outputs text to the standard output stream (StdOut). Such programs simply hang. How lame. Yes, even if you try to capture StdErr with StdErr.ReadAll. So very lame. How to: Use Anonymous Pipes for Local Interprocess Communication. Anonymous pipes provide interprocess communication on a local computer. They offer less functionality than named pipes, but also require less overhead. You can use anonymous pipes to make interprocess communication on a local computer easier. You cannot use anonymous pipes for communication over a network. The parent process then sends a user-supplied string to the child process. The following example shows the server process.

The following example shows the client process. How to: Use Named Pipes for Network Interprocess Communication. Named pipes provide interprocess communication between a pipe server and one or more pipe clients. They offer more functionality than anonymous pipes, which provide interprocess communication on a local computer. Named pipes support full duplex communication over a network and multiple server instances, message-based communication, and client impersonation, which enables connecting processes to use their own set of permissions on remote servers. MSDN Blogs. The Orcas October Community Technology Preview (CTP) includes new types that make it easy for developers to use pipes from managed code. Pipes are used for inter-process communication (IPC) between processes running on the same machine, or processes running on any other Windows machine within a network.

We've added support for both anonymous and named pipes. The new pipe types can be found in System.Core.dll within the System.IO namespace. Note that after the October CTP went out, we moved the pipe types from System.IO to System.IO.Pipes, so the types will be in the new namespace in all future CTPs. Anonymous Pipes Anonymous pipes are character-based and are half-duplex. They cannot communicate over the network and support only a single server instance. Example 1: Anonymous Pipes The following example demonstrates sending a string from a parent process to a child process. Parent Process Process process = new Process(); process.StartInfo.FileName = "child.exe"; process.Start(); process.Close();

Using Pipes. Using Message Queuing. Writing a Message Queuing Application using Visual Basic. Networking and Internet - Windows app development. Named Pipes. A named pipe is a named, one-way or duplex pipe for communication between the pipe server and one or more pipe clients. All instances of a named pipe share the same pipe name, but each instance has its own buffers and handles, and provides a separate conduit for client/server communication. The use of instances enables multiple pipe clients to use the same named pipe simultaneously. Any process can access named pipes, subject to security checks, making named pipes an easy form of communication between related or unrelated processes. Named pipes can be used to provide communication between processes on the same computer or between processes on different computers across a network.

If the server service is running, all named pipes are accessible remotely. If you intend to use a named pipe locally only, deny access to NT AUTHORITY\NETWORK or switch to local RPC. For more information, see the following topics: Named Pipe Client. Creating Named Shared Memory. To share data, multiple processes can use memory-mapped files that the system paging file stores. First Process #include <windows.h> #include <stdio.h> #include <conio.h> #include <tchar.h> #define BUF_SIZE 256 TCHAR szName[]=TEXT("Global\\MyFileMappingObject"); TCHAR szMsg[]=TEXT("Message from first process.

"); int _tmain() { HANDLE hMapFile; LPCTSTR pBuf; hMapFile = CreateFileMapping( INVALID_HANDLE_VALUE, // use paging file NULL, // default security PAGE_READWRITE, // read/write access 0, // maximum object size (high-order DWORD) BUF_SIZE, // maximum object size (low-order DWORD) szName); // name of mapping object if (hMapFile == NULL) { _tprintf(TEXT("Could not create file mapping object (%d). \n"), GetLastError()); return 1; } pBuf = (LPTSTR) MapViewOfFile(hMapFile, // handle to map object FILE_MAP_ALL_ACCESS, // read/write permission 0, 0, BUF_SIZE); if (pBuf == NULL) { _tprintf(TEXT("Could not map view of file (%d). Second Process Related topics.