How Photon App Send/Recv Message

I have a Photon sub-process spawned by the main process(not a photon
application), I need to transfer data between the main process and the
photon process.

My program is simplified to be:
Myprog.cpp:
main()
{
chid = ChannelCreate( 0 );
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANEL, 0);
spawn(NO_WAIT, “Myphoton”, “Myphoton”, chid, NULL);
MsgSend(coid, &msg_send, sz1, &msg_rcv, sz2);
}

MyPhoton.c:
void input_proc( void *data, int rcvid, void *msg, size_t msglen )
{
SetResource;
MsgReply(rcvid, &msg_return, size);
return Pt_CONTINUE;
}

main()
{
coid = ConnectAttach(chid);
PhAppAddInput(0, getppid(), input_pro, msg);
PtMainLoop();
}

It seems that the main process can not talk with the photon process.
Does any one has sone idea on interprocess communication like this?
Thanks for any help. I am working under QNX6.2NC.

Lily <fanxm0712@yahoo.ca> wrote:

I have a Photon sub-process spawned by the main process(not a photon
application), I need to transfer data between the main process and the
photon process.

My program is simplified to be:
Myprog.cpp:
main()
{
chid = ChannelCreate( 0 );
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANEL, 0);
spawn(NO_WAIT, “Myphoton”, “Myphoton”, chid, NULL);
MsgSend(coid, &msg_send, sz1, &msg_rcv, sz2);

This code creates a channel, connects to it, spawns some program, and
then sends to its own channel. You are not sending to the child
process here – you’re sending to yourself. And unless this process
really is multithreaded, there’s nobody who can receive the message
while you’re trying to send it…

For the parent to be able to send to its child, the parent must wait
until the child has created a channel. Then, the parent must find out
the channel ID and connect to it.

In general, it’s simpler to implement a protocol where it’s the child
that sends to the parent rather than the other way around. Even if you
need it to be the other way around, it might make sense for the child to
send to the parent once – this would give the parent a simple way to
wait until the child has a channel, and reeceive the channel ID in the
message.

Since the child is a Photon program, the channel will be created for you
as soon as you call PtAppAddInput() or PtCreateChannel().
PtCreateChannel() also gives you the channel ID, which you can then send
to the parent.

After receiving this message, the parent can get rid of its channel and
connect to the child’s channel, and the child can close its connection
to the parent, and from then on it’ll be the parent that sends to the
child.

Wojtek Lerch wrote:

Lily <> fanxm0712@yahoo.ca> > wrote:

I have a Photon sub-process spawned by the main process(not a photon
application), I need to transfer data between the main process and the
photon process.


My program is simplified to be:
Myprog.cpp:
main()
{
chid = ChannelCreate( 0 );
coid = ConnectAttach( 0, 0, chid, _NTO_SIDE_CHANEL, 0);
spawn(NO_WAIT, “Myphoton”, “Myphoton”, chid, NULL);
MsgSend(coid, &msg_send, sz1, &msg_rcv, sz2);


This code creates a channel, connects to it, spawns some program, and
then sends to its own channel. You are not sending to the child
process here – you’re sending to yourself. And unless this process
really is multithreaded, there’s nobody who can receive the message
while you’re trying to send it…

For the parent to be able to send to its child, the parent must wait
until the child has created a channel. Then, the parent must find out
the channel ID and connect to it.

In general, it’s simpler to implement a protocol where it’s the child
that sends to the parent rather than the other way around. Even if you
need it to be the other way around, it might make sense for the child to
send to the parent once – this would give the parent a simple way to
wait until the child has a channel, and reeceive the channel ID in the
message.

Since the child is a Photon program, the channel will be created for you
as soon as you call PtAppAddInput() or PtCreateChannel().
PtCreateChannel() also gives you the channel ID, which you can then send
to the parent.

After receiving this message, the parent can get rid of its channel and
connect to the child’s channel, and the child can close its connection
to the parent, and from then on it’ll be the parent that sends to the
child.

Thnks Wojtek, I’ll try it.