Code Examples. More...
Code Examples.
The following example shows how to create a commport, sending and receiving messages on it and then deleting it.
As a first step, a communication port is created. For creating a commport we can specify a required communication port id, if the commport is going to serve as a well known server. This can be chosen from clIocServices.h file. If 0 is passed for commPortId then the IOC will chose one commomuincation port id for the application. For sending and receiving through this communication port the communication handle should be used.
Here we can see how a message can be sent to a destination. The protocol field is a must for sending a packet, and it should be chosen from clIocProtocols.h file. The data to be sent should be passed as a buffer message. And the receiver address can be a physical, logical or a multicast address.
The clIocReceive() call will block on the commport for receiving a message. The call expects a valid buffer message handle to receive the data. On receiving some data the IOC unblocks the receiver thread, which is blocked on the commport. All the information relating to the message received( like sender info, length of the message, protocol for analysing the message), will be present in recvParam.
For deleting a commport a valid commPortHandle must be passed. And before calling this API we need make sure that no thread is waiting for any data on this commport.