Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Smile )
  • 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 Smile 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? Smile 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 Wink


Best regards,
Honza
  • Attachment: IPC.zip
    (Size: 3.22KB, Downloaded 306 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 messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

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 Smile )
  • 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 Smile 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? Smile 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 Wink


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 messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

Hello all!

Thanks Ion, let me know how did it work! Wink

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

Best regards,
Honza
  • Attachment: IPC.zip
    (Size: 8.01KB, Downloaded 300 times)
Re: Simple IPC using Sockets [message #25438 is a reply to message #25434] Tue, 23 February 2010 17:39 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

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

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

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 messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

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 Smile 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
icon9.gif  Re: Simple IPC using Sockets [message #25522 is a reply to message #25224] Sat, 27 February 2010 13:54 Go to previous messageGo to next message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

I just found it hangs on exiting when run on multicore processor Sad 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 #31379 is a reply to message #25522] Sat, 26 February 2011 11:24 Go to previous messageGo to next message
tojocky is currently offline  tojocky
Messages: 607
Registered: April 2008
Location: UK
Contributor

Hello Honza,

How about to improve a little your IPC?

I propose to add possibility to integrate named pipes. In the local computer and speed LAN the communication is more faster.

I will try to change your code and propose a variant with named pipes. Sure if you allow to change your code.

Some utils links:
http://msdn.microsoft.com/en-us/library/aa178138(v=sql.80).a spx
http://www.chromium.org/developers/design-documents/inter-pr ocess-communication

[Updated on: Sat, 26 February 2011 11:25]

Report message to a moderator

Re: Simple IPC using Sockets [message #31380 is a reply to message #31379] Sat, 26 February 2011 11:56 Go to previous message
dolik.rce is currently offline  dolik.rce
Messages: 1758
Registered: August 2008
Location: Czech Republic
Senior Contributor

Hi Ion,

Well, why not Smile 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

Honza
Previous Topic: Fix for examples/CodeMetric
Next Topic: Compiling MPIR in TheIde
Goto Forum:
  


Current Time: Tue Aug 20 15:57:01 CEST 2019

Total time taken to generate the page: 0.00812 seconds