MsgSend() on a network

I am trying to pass messages between two processes on different nodes and I
have created two simple processes server and client. The server lies on a
machine called avatar.usc.edu and I am trying to pass messages. The program
just hangs on the client.


The client hangs on netmgr_strtond() call.


The code is attached.
Any help is appreciated

Thanks
Srikanth

Client Code…



#include <stdlib.h>
#include <stdio.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/netmgr.h>
#include <share.h>
#include “struct.h”


int main(void)
{
msg_contents_t msg;
int coid;
int retval;
int pid;
int nd;
nd = netmgr_strtond(“avatar.usc.edu”, NULL);
//coid = name_open(MY_NAME ,0);
pid = netmgr_remote_nd(nd,coid);
chid = ChannelCreate(0);
coid = ConnectAttach(pid, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1) {
perror(“Connect Attach failed”);
return(EXIT_FAILURE);
}
printf(“Enter some text to send to server: “);
scanf(”%s”, msg.text);
printf(“Client is going to send %s \n”, msg.text);
retval = MsgSend(pid, &msg, sizeof(msg), NULL, 0);
if(retval == -1) {
perror(“MsgSend failed”);
}

return(EXIT_SUCCESS);
}







Server Code…




#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <sys/iofunc.h>
#include <sys/dispatch.h>
#include <sys/neutrino.h>
#include “struct.h”

int main(void)
{
name_attach_t* attach;
int rcvid;
msg_contents_t msg;

attach = name_attach(NULL, SERVER_NAME, 0);
if(attach == NULL) {
perror(“name_attach() failed”);
exit(EXIT_FAILURE);
}
while(1) {
rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), NULL);
if (rcvid == -1) {
perror(“MsgReceive failure”);
//don’t exit program, this isn’t a fatal error
continue;
//just break out of current MsgReceive loop and try again
}
else if (rcvid == 0) { //if the receive id is
0, we’ve received a pulse
printf(“Message passing server has received a pulse. \n”);
if(msg.pulse.code == _PULSE_CODE_DISCONNECT) {
printf(“Server has received a pulse telling it the client has
terminated\n”);
}
else {
printf(“Server received a pulse for some reason other than
that the client has terminated\n”);
}
printf(“The pulse code was: %d\n”, msg.pulse.code);
printf(“Note that any negative pulse code was sent by the OS
for informational purposes\n”);
}
else {
printf(“Server received a message. The content is: %s \n”,
msg.text);
MsgReply(rcvid, EOK, 0, 0);
}
}
name_detach(attach, 0);
return(EXIT_SUCCESS);
}

Hi,

Take a look at the following QNX Knowledge Base entry for an example of how
to connect to a process on another node.

http://www.qnx.com/support/sd_bok/solution.qnx?10342

Regards,

Joe

“Srikanth Saripalli” <srik@usc.edu> wrote in message
news:aj5107$s5b$1@inn.qnx.com

I am trying to pass messages between two processes on different nodes and
I
have created two simple processes server and client. The server lies on a
machine called avatar.usc.edu and I am trying to pass messages. The
program
just hangs on the client.


The client hangs on netmgr_strtond() call.


The code is attached.
Any help is appreciated

Thanks
Srikanth

Client Code…



#include <stdlib.h
#include <stdio.h
#include <sys/iofunc.h
#include <sys/dispatch.h
#include <sys/types.h
#include <sys/stat.h
#include <fcntl.h
#include <sys/netmgr.h
#include <share.h
#include “struct.h”


int main(void)
{
msg_contents_t msg;
int coid;
int retval;
int pid;
int nd;
nd = netmgr_strtond(“avatar.usc.edu”, NULL);
file://coid = name_open(MY_NAME ,0);
pid = netmgr_remote_nd(nd,coid);
chid = ChannelCreate(0);
coid = ConnectAttach(pid, 0, chid, _NTO_SIDE_CHANNEL, 0);
if(coid == -1) {
perror(“Connect Attach failed”);
return(EXIT_FAILURE);
}
printf(“Enter some text to send to server: “);
scanf(”%s”, msg.text);
printf(“Client is going to send %s \n”, msg.text);
retval = MsgSend(pid, &msg, sizeof(msg), NULL, 0);
if(retval == -1) {
perror(“MsgSend failed”);
}

return(EXIT_SUCCESS);
}







Server Code…




#include <stdlib.h
#include <stdio.h
#include <errno.h
#include <sys/iofunc.h
#include <sys/dispatch.h
#include <sys/neutrino.h
#include “struct.h”

int main(void)
{
name_attach_t* attach;
int rcvid;
msg_contents_t msg;

attach = name_attach(NULL, SERVER_NAME, 0);
if(attach == NULL) {
perror(“name_attach() failed”);
exit(EXIT_FAILURE);
}
while(1) {
rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), NULL);
if (rcvid == -1)

perror(“MsgReceive failure”);
file://don’t exit program, this isn’t a fatal error
continue;
file://just break out of current MsgReceive loop and try again
}
else if (rcvid == 0) { file://if the receive
id is
0, we’ve received a pulse
printf(“Message passing server has received a pulse. \n”);
if(msg.pulse.code == _PULSE_CODE_DISCONNECT) {
printf(“Server has received a pulse telling it the
client has
terminated\n”);
}
else {
printf(“Server received a pulse for some reason
other than
that the client has terminated\n”);
}
printf(“The pulse code was: %d\n”, msg.pulse.code);
printf(“Note that any negative pulse code was sent by the
OS
for informational purposes\n”);
}
else {
printf(“Server received a message. The content
is: %s \n”,
msg.text);
MsgReply(rcvid, EOK, 0, 0);
}
}
name_detach(attach, 0);
return(EXIT_SUCCESS);
}