Share My Creation Interprocess Comms - Controller Widget and example clients.

Hi,

I run a headless client app that gets data over WiFi from an embedded controller and stores it in an sQlite DB. I call this the uServer.

Originally if I wanted to shut it down I just killed the process. This is a bad idea because the process could be shut down in the middle of a db write.

Quite often I just want to suspend the process from writing to the db and checkpoint the db and close so I can copy the db file for other purposes.

So I made a Inter-process Comm's server (IPCS) that uses localhost (127.0.0.1) as the server is running on the same machine as the uServer. You could just as easily use a remote IP address.

The IPCS has a simple user interface:

userverpowermoncontroller-png.101933


The server creates a server socket on port 17170 and listens for server clients that poll using a timer every five seconds or so.

If a client is running a connection is made and commands may be sent to the client and data received from it.

I use five commands:

  • GET_DATA_I Client doesn't change state just replies with data
  • SHUTDOWN_I Client shuts down after performing any housekeeping such as database check points, file closes etc.
  • CHEKPOINT_I Client suspends normal activities, does a checkpoint (in my app) then resumes
  • RUN_I Restarts a suspended client
  • PAUSE_I Client suspends normal activities, does a checkpoint (in my app) then closes db and waits in suspend state
I have attached three projects in the zip:

  • Inter-process Comm Server
  • Interprocess Client Example that will run and produces dummy data
  • uServer (pmon_userver) This will not run properly as you need to be able to connect to the embedded controller.
    I included it so you can see how the IPCS can be used with a real system.

Of course the IPCS will need to be modified to suit whatever headless apps you want to control, however the code in these projects is a good starting point.

WARNING:
The custom types for command and data transmission must be specified in the main program, not the ipcComms class per Erel. If this isn't done the serializator that processes the bytes to object and vice versa fails at the client and the server end.


Hope someone finds this useful

Best Regards
Rob
 

Attachments

  • uServerPowerMonController.png
    uServerPowerMonController.png
    82.8 KB · Views: 2,336
  • InterProcCommsLocalHost_ServerAndClients.zip
    492.7 KB · Views: 225
Top