Package Overview

The Ipc package allows you to use a TCP/IP reliable socket to let two programs communicate with each other. This is called interprocess communication (IPC). IPC is used when you need "live" communication between two separate programs (not necessarily running on the same machine), such as Riverbed Modeler and op_runsim, when the progress bar is updated by op_runsim during a simulation. The interprocess connection procedure is shown in detail in the following steps:

  1. Program A (Riverbed Modeler, for example) calls Prg_Ipc_Port_Create_Listen() once to create a port and starts listening on that port.
  2. Program B (for example, op_runsim) calls Prg_Ipc_Port_Connect_To() to create a port on its side and then connects to program A.
  3. Now both programs can call Prg_Ipc_Packet_Send() to send data to the other side, which causes the packet handler registered for the other side's port to be called. Note that once two programs are communicating on a certain port, no other programs can connect on the same port until the original connection is destroyed.
  4. Communication terminates when either side calls Prg_Ipc_Port_Destroy(), thereby closing its port. The other side is notified of the port closure through its packet handler, which uses a callback of type PrgT_Ipc_Packet_Handler.

Both programs either agree on a fixed TCP/IP port number to connect, or program A listens on a dynamically determined port number and passes that port number to program B via arguments defined in Prg_Ipc_Port_Create_Listen().

When a connection is made between programs, there are times when one program should not proceed until the other program is ready. In this case, you can use Prg_Ipc_Wait_For_Port() to block one program until data is received from the connected port, or the specified wait time elapses. You can also use Prg_Sleep() to tell the program to sleep for a specified number of seconds. If an IPC connection is requested or a timer goes off while the program is sleeping, the interrupt is processed and then the program goes back to sleep. Prg_Timer_Schedule() or Prg_Timer_With_State_Schedule() can be used to schedule the execution of a handler function at a specified time. If you want the handler to be called multiple times, you should schedule another timer from inside the handler. To cancel a scheduled execution of a handler, use Prg_Timer_Cancel().