Communicating Processes
Really, I'm strong believer of communication. Actually in every form, be it written, spoken, sign and signals. It is really the input of all facet of learning. And who does not want to learn?
Communicating Processes means two or more processes will communicate among them. Simple example of it is two processes communicating with each other. And the media is of course information bus. This information bus could be almost anything. Processes talks over wireless, wired networks, over physical media other than what we call network today. The most fundamental aspect of communication is - Signal processing. This is in the physics and engineering domain. But our topic here is digital communication. Particularly, using Windows systems.
Usually the steps to achieve a good / effective / reliable communication, the following steps are important -
- Choose the infromation Bus: Network, Physical Media, storage systems etc.
- Get a way to programmatically Talk: It is to transmit junk back and forth to see the bus is active and raw.
- Devise protocol(s) to have good / effective / reliable communications
- Incrementally implement.
- Test & Debug.
In order to achieve a quick ( Well, fairly quick I would say ! ) implementation, I took the simplest approach first. It is the shared memory technique in user level programming. In a hurry, I will have few bad pointer references, and user level would save lot of pain and agony if you understand what I mean. Now shared memory is thru file mapped paradigm in Windows system. So the information Bus I selected is shared memory.
In order to make things simple, I picked a pair of such information bus, each in one direction. Here we can have a choice to communicate from one end to other what bus would be used in which direction or we can have an apriori assumption about which bus would take what direction. For shared memory, I just took the apriori assumption by giving explict name like: client shared memory, server shared memory. The naming is purely based on who would be using the bus for writing information to the bus. So Server shared memory information bus is for server to write and client to read. Things are simple. Why? Because by the time client or server starts, everything about the bus is already in place. The just blindly need to communicate with each other, just like the way we talk and never thought of the atomosphare ( particularly eather ) that acts as a bus.
Once the bus is in place and in raw mode, we can talk - no matter how nonsensical they are :). This is to see information is getting exchanged. Albiet, both side having bad experiences in learing, if anything since it is like talking rubbish, and no communication at all.
Now the next step is to carry the payload across with meaningful context. Remember in older days, when we had very noisy telecom line for long distance trunk system and we use to loose context and used asked for what what, please repeat etc.
So this meaningful contex is really the protocol. In this particular protocol we had the following -
1) A payload would be processed only once by the destination since that payload was conveyed only once.
2) The payload with associated protocol information is called message. Each message is atomically processed.
3) Every message has to be processed.
Now since a message is processed only once, consumption of the message means it is gone from the pipe once processed. In our case the reader will atomically read, and if it is indeed a message from writer, it will atomically erase. On the writer side, it will make sure that the pipe/bus has no message ( it is single message channel) and atomically write the whole message.
The payload is wrapped with hdr informations that indicates say: client id, sequence number, message length etc. The message itself is within the total payload.
Following these simple rules, it is fairly easy to cookup a base line information bus for communicating processes.
Enjoy!
-pro
References (1)
-
Response: happy new year images
Reader Comments