|
|
Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » Simple IPC using Sockets
Simple IPC using Sockets [message #25224] |
Mon, 15 February 2010 00:36 ![Go to next message Go to next message](theme/default/images/down.png) |
|
Hello All,
I would like to share one very small class I wrote. It is simple object providing mostly automatic and very easy to set up interprocess communication. Example of usage is attached as well.
Basic goals:- Simple to use
- No specialized server app required
- Everything should be as automatic as possible
- Programmer can simply define communication protocol
- Communication is done via Sockets, no shared memory (related to the next point)
- It is not meant to be robust, but to allow easy and rapid development for small scale apps.
Implemented features:- Everything mentioned in goals (I hope
)
- Protocol is specified using Callbacks, so rules can have different forms (e.g: single function with switch for handling messages OR several functions, each is defining one rule (used in example app) OR even pipeline style processing, where each function modifies the output of previous function and then passes it to next)
- One instance of application performs the tasks of server in separate thread. This role is automatically picked up by another instance when the previous server is closed.
- Optionally, programmer can start/stop server thread.
Warning: This package was not extensively tested yet, you might experience all sort of bad things from loss of information to deadlocks. It did not happen to me, but it doesn't mean it can't happen There is a high probability that I will develop this code further in future, since I wan't to use it in one of my projects.
About the example app: It's a console app that does nothing else then manages a list of strings (Vector<String> internally) from a simple shell. You can display it's content (command "show"), add ("add something") and delete items ("del number"). To exit, type "quit". Nothing much, heh? The interesting part is that if you open few more instances of this application, they will all behave as if they worked with single variable (but they of course do not, they just keep their own variable in sync). And this magic is done in ~50 lines of code, out of which is ~4O lines are definitions of protocol.
If you think this is interesting/useful please let me know. Suggestions for further development are welcomed too
Best regards,
Honza
-
Attachment: IPC.zip
(Size: 3.22KB, Downloaded 526 times)
[Updated on: Mon, 15 February 2010 01:43] Report message to a moderator
|
|
|
Re: Simple IPC using Sockets [message #25247 is a reply to message #25224] |
Mon, 15 February 2010 14:43 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
|
Nice,
I will test!
dolik.rce wrote on Mon, 15 February 2010 01:36 | Hello All,
I would like to share one very small class I wrote. It is simple object providing mostly automatic and very easy to set up interprocess communication. Example of usage is attached as well.
Basic goals:- Simple to use
- No specialized server app required
- Everything should be as automatic as possible
- Programmer can simply define communication protocol
- Communication is done via Sockets, no shared memory (related to the next point)
- It is not meant to be robust, but to allow easy and rapid development for small scale apps.
Implemented features:- Everything mentioned in goals (I hope
)
- Protocol is specified using Callbacks, so rules can have different forms (e.g: single function with switch for handling messages OR several functions, each is defining one rule (used in example app) OR even pipeline style processing, where each function modifies the output of previous function and then passes it to next)
- One instance of application performs the tasks of server in separate thread. This role is automatically picked up by another instance when the previous server is closed.
- Optionally, programmer can start/stop server thread.
Warning: This package was not extensively tested yet, you might experience all sort of bad things from loss of information to deadlocks. It did not happen to me, but it doesn't mean it can't happen There is a high probability that I will develop this code further in future, since I wan't to use it in one of my projects.
About the example app: It's a console app that does nothing else then manages a list of strings (Vector<String> internally) from a simple shell. You can display it's content (command "show"), add ("add something") and delete items ("del number"). To exit, type "quit". Nothing much, heh? The interesting part is that if you open few more instances of this application, they will all behave as if they worked with single variable (but they of course do not, they just keep their own variable in sync). And this magic is done in ~50 lines of code, out of which is ~4O lines are definitions of protocol.
If you think this is interesting/useful please let me know. Suggestions for further development are welcomed too
Best regards,
Honza
|
|
|
|
Re: Simple IPC using Sockets [message #25434 is a reply to message #25224] |
Tue, 23 February 2010 12:57 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
|
Hello all!
Thanks Ion, let me know how did it work! ![Wink](images/smiley_icons/icon_wink.gif)
Here is new version. Some little bugs were fixed and new class, IPC2, was added. This new class extends the possibilities of IPC with broadcast and client-to-client messages. The examle application was extended a bit to show new capabilities. Also user documentation is enclosed and up-to-date.
The communication is implemented using polling. Related to this, I should mention that in console mode, the package uses bazaar/Timer (thanks kohait00!) and with GUI flag it uses functions from CtrlCore.
And of course, I'm still opened to suggestions... ![Wink](images/smiley_icons/icon_wink.gif)
Best regards,
Honza
-
Attachment: IPC.zip
(Size: 8.01KB, Downloaded 498 times)
|
|
|
Re: Simple IPC using Sockets [message #25438 is a reply to message #25434] |
Tue, 23 February 2010 17:39 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
|
Honza,
Preview version worked only on win32. on linux did not work. I had not sufficient time for complete test and sugestion.
One good practice is google Chrome:
http://dev.chromium.org/developers/design-documents/inter-pr ocess-communication
I will test the latest version.
Regards,
Ion Lupascu (tojocky)
dolik.rce wrote on Tue, 23 February 2010 13:57 | Hello all!
Thanks Ion, let me know how did it work! ![Wink](images/smiley_icons/icon_wink.gif)
Here is new version. Some little bugs were fixed and new class, IPC2, was added. This new class extends the possibilities of IPC with broadcast and client-to-client messages. The examle application was extended a bit to show new capabilities. Also user documentation is enclosed and up-to-date.
The communication is implemented using polling. Related to this, I should mention that in console mode, the package uses bazaar/Timer (thanks kohait00!) and with GUI flag it uses functions from CtrlCore.
And of course, I'm still opened to suggestions... ![Wink](images/smiley_icons/icon_wink.gif)
Best regards,
Honza
|
|
|
|
Re: Simple IPC using Sockets [message #25439 is a reply to message #25438] |
Tue, 23 February 2010 17:54 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
|
tojocky wrote on Tue, 23 February 2010 17:39 | Honza,
Preview version worked only on win32. on linux did not work.
|
Funny, I never tested on windows and yet it works (only) there I will try on some other machines, to see if I can reproduce your problem. On ubuntu 9.10 and Arch Linux, it works fine.
Anyway, thank you for your interest!
Honza
|
|
|
Re: Simple IPC using Sockets [message #25522 is a reply to message #25224] |
Sat, 27 February 2010 13:54 ![Go to previous message Go to previous message](theme/default/images/up.png) ![Go to next message Go to next message](theme/default/images/down.png) |
|
I just found it hangs on exiting when run on multicore processor So long for a simple class... I'll try to fix it of course, but it may take a lot of time as I'm not really skilled in MT.
Honza
|
|
|
|
Re: Simple IPC using Sockets [message #31380 is a reply to message #31379] |
Sat, 26 February 2011 11:56 ![Go to previous message Go to previous message](theme/default/images/up.png) |
|
Hi Ion,
Well, why not I know that the sockets are not ideal and actually I was thinking about rewriting this as well. My idea was to use DBus, as it is more or less standard solution these days and can be used to interact with other applications as well... Or maybe the DBus could be completely separate package. Also, if I am not mistaken, the most common DBus server implementation uses named pipes for comunication as well.
But back to the topic: If you wish so and have the time, you can modify this package as you want. I didn't have time to develop this for very long time and didn't even need to use it, so I'll be more than happy if someone improves it ![Wink](images/smiley_icons/icon_wink.gif)
Honza
|
|
|
Goto Forum:
Current Time: Sun Sep 01 07:34:16 CEST 2024
Total time taken to generate the page: 0.00487 seconds
|
|
|