Problem on client-server communication

Since it is not convinient to input Chinse in QNX, I use my poor English to discribe my problem.
Now I have two code, one is client.c and the other is server.c, as shown below. I spawn a process to run the client on another mashine in server.
The client should send a message to the server, and the server receive the data Here is the result after ./server, I am quite confused about the result, expecially the received message, could some one explain it? Thanks in advance!

./server

MsgReceive…
received something:
Remote side 65542 connected to server
MsgReceive…
received something:
server received a message of from client
MsgReceive…
received something:
server received a message of from client
MsgReceive…
received something:
from clientived a message of :0
MsgReceive…
received something:
server received a message of --client data-- from client

Client received server reply: server reply msg to client!
MsgReceive…
recvId: 0
MsgReceive…
received something:
server received a message of --client data-- from client
MsgReceive…
recvId: 0

//server.c
#include <errno.h>
#include <time.h>
#include <string.h>
#include <spawn.h>
#include <sys/neutrino.h>
#include <sys/netmgr.h>
#include <sys/dispatch.h>

struct Message
{
// This structure contains timer events
struct _pulse timerPulse;

// This is user event message data
char data[100];
}msg,replyMsg,emptyReply;



int main()

{

name_attach_t *nameAttach; // QNX global name struct

int channelId;

int connectId;

int processId = 0; // Ourselves

int recvId;

int ret;

pid_t pid;
char *file="/net/node2/home/client";
char *arg_list[] = {file, NULL};
struct inheritance inherit;
inherit.flags = SPAWN_SETND;
inherit.nd = netmgr_strtond(“node2”,NULL);

if ((nameAttach = name_attach(NULL, “myname”, NAME_FLAG_ATTACH_GLOBAL)) == NULL)

{

printf( “name_attach Error!”);

exit (-1);

}

channelId = nameAttach->chid;



// Connect to the channel to be able to receive messages

if ((connectId = ConnectAttach_r(ND_LOCAL_NODE, processId, channelId, _NTO_SIDE_CHANNEL, 0)) < 0)

{

printf(“Connection failed on channel %d due to %s”, channelId, strerror(abs(connectId)));

exit(-1);

}




if(pid = spawn(file,0,NULL,&inherit,arg_list,NULL) == -1)
{
printf(“spawn error!”);
exit(-1);
}

// Receive a message or timer pulse

while(1)
{

if ((recvId = MsgReceive_r(channelId, &msg, sizeof(msg), NULL)) < 0)

{

printf("Error MsgReceive! ");

exit(-1);

}

else

{

// Determine if we received a message or timer pulse

printf(“MsgReceive…\n”);
if (recvId == 0)

{

printf(“recvId: %d\n”,recvId);
switch (msg.timerPulse.code)

{

case _PULSE_CODE_DISCONNECT:

// Remote side disconnecting via name_close() from a

// name_open (this only occurs for a server process

ConnectDetach_r(msg.timerPulse.scoid);

break;

case _PULSE_CODE_UNBLOCK:

// Sender hit by a signal so release them to process it

if ((ret = MsgReply_r(recvId, 0, &emptyReply, sizeof(emptyReply))) < 0)

{

printf(“Error %s while trying to reply to sender over connection %d on channel %d”, strerror(abs(ret)), connectId, channelId);

}

break;

case _PULSE_CODE_THREADDEATH:

case _PULSE_CODE_COIDDEATH:

// Remote side died/exited!

break;

default:

// Timer pulse received. Do timer processing…

break;

}

}

else

{

// Reply to a name_open() call for servers

printf(“received something:\n”);
if (msg.timerPulse.type == _IO_CONNECT)

{

MsgReply_r(recvId, EOK, NULL, 0);

printf(“Remote side %d connected to server\n”, recvId);

}

else

{

// Process the message…

printf (" server received a message of %s from client\n", msg.data);



// Reply to unblock the other side.

sprintf(replyMsg.data,“server reply msg to client!”);

printf("\n");
MsgReply_r(recvId, 0, &replyMsg, sizeof(replyMsg));

}

}

}

}
}

//client.c
#include <errno.h>
#include <time.h>
#include <string.h>
#include <sys/neutrino.h>
#include <sys/netmgr.h>
#include <sys/dispatch.h>

struct Message
{
// This structure contains timer events
struct _pulse timerPulse;

// This is user event message data
char data[100];
}msg,replyMsg;


int main()

{

int connectId; // Connect Id returned by QNX O/S


int ret;

int msgSize;

msgSize = sizeof(msg);
if ((connectId = name_open(“myname”, NAME_FLAG_ATTACH_GLOBAL)) < 0)

{

printf(“Error!”);

exit(-1);

}



// Sends a message to the server



sprintf(msg.data,"–client data–");
printf("\n");

if ((ret = MsgSend_r(connectId, &msg,msgSize, &replyMsg,sizeof(replyMsg))) < 0)

{

printf(“Error %s %d while trying to send message over connection %d”, strerror(abs(ret)), ret, connectId);

exit(-1);

}

printf (“Client received server reply: %s\n”, replyMsg.data);

name_close(connectId);
return 0;
}