SimpleIPC: what changed
Revision 0 to 1. Removed lines have a minus sign; added lines have a plus sign.
Title: SimpleIPC
| Old | New | Line | |
|---|---|---|---|
| 1 | + | **Simple IPC** is a Free Pascal unit (and Lazarus components) that allows interprocess communication (IPC) between Free Pascal programs. | |
| 2 | + | ||
| 3 | + | It allows two executables to communicate. | |
| 4 | + | ||
| 5 | + | ## Advantages of SimpleIPC | |
| 6 | + | ||
| 7 | + | You can create communication systems without requiring low level sockets programming of your own. SimpleIPC does the grunt work of IPC for you and makes a nice high level wrapper around lower level IPC mechanisms, so you don't have to program them yourself. | |
| 8 | + | ||
| 9 | + | SimpleIPC can be used to communicate between programs to make simple communication systems, plugin systems and much more, | |
| 10 | + | ||
| 11 | + | ### Hint : Multiuser Systems | |
| 12 | + | ||
| 13 | + | On multiuser systems, eg, Unix systems, in Global Mode, note that the pipe that IPC creates must have a distinctive name between individual users. Its usual to set the ServerID to the application name so, add the user name to that - | |
| 14 | + | ||
| 15 | + | ``` pascal | |
| 16 | + | CommsServer := TSimpleIPCServer.Create(Nil); | |
| 17 | + | CommsServer.ServerID:='MyAppName' {$ifdef UNIX} + '-' + GetEnvironmentVariable('USER'){$endif}; | |
| 18 | + | CommsServer.OnMessageQueued:=@CommMessageReceived; | |
| 19 | + | CommsServer.Global:=True; | |
| 20 | + | CommsServer.StartServer({$ifdef WINDOWS}False{$else}True{$endif}); // start listening, threaded | |
| 21 | + | ``` | |
| 22 | + | ||
| 23 | + | Without the user name being added, you risk all instances of the App trying to use the same named pipe and, obviously permissions do not allow that. | |
| 24 | + | ||
| 25 | + | ## Use Cases | |
| 26 | + | ||
| 27 | + | The [[Help protocol|Lazarus help system]] itself, uses SimpleIPC. | |
| 28 | + | ||
| 29 | + | Some [[fpGUI]] tools and demos use IPC, for example, to detect if the program is already running (single instance) | |
| 30 | + | ||
| 31 | + | ## Send Messages to Other Programming Languages | |
| 32 | + | ||
| 33 | + | For IPC between Free Pascal programs and other programs written in any language (C++, Delphi, GoLang, etc.) see [[SimpleIPC Library]] which allows you to use SimpleIPC not just in FPC and Lazarus, but in multiple programming languages. | |
| 34 | + | ||
| 35 | + | ## See also | |
| 36 | + | ||
| 37 | + | - [Official FCL documentation for SimpleIPC unit](https://www.freepascal.org/docs-html/current/fcl/simpleipc/index.html) | |
| 38 | + | ||
| 39 | + | --- | |
| 40 | + | *From the Free Pascal wiki, page "SimpleIPC", as it stood on 2022-05-03 after a change by Dbannon, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* | |
| 41 | + | Category: FPC | |
| 42 | + | Category: Inter-process communication | |
| 43 | + | Category: Lazarus |
