How to send message from server?

I want to send message from server using the same attached point from which it has recieved a message from client…

You can only do a MsgDeliverEvent() use the rcvid. If that is not enough, the client has to setup a channel for the server to send message to.

Does that mean we need to create another attachpoint on the client side?

Yes. Typicaly that is not how it`s done though, that think of break the server/client idea. If the server has to send something to the client, you can :

  • Have the server delay for the reply() until there is something to send, but that means the client blocks.
  • Have the client request notification io_notify()/select() when data is available. That means the server sends and event to the client indicating there is data. Upon reception of that event the client sends a message to get the data. That`s how tcpip works with select() and read() for example.

Message that is sent from the client is different from the message that is recieved from the server…

This happens when gns service is run…without running gns and creating an attachpoint locally there is no problem in data transfer…

Don’t understand exaclty what you are saying, but I suspect you problem is in handling IO_CONNECT message.

Check the documentation on name_*()

if i send the message as 123456,but message recieved by server is always 13138…

i dont know the reason…
can u plzz help me with this…

The reason is a bug in your code, but I don`t have a clue what it is.

In other words Mario is saying you’ll need to post your code if you want any further help.

Tim

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/dispatch.h>

#define ATTACH_POINT “myname”

/*** Server Side of the code ***/
int main() {
name_attach_t *attach;
int rcvid,msg;

/* Create a local name (/dev/name/local/…) */
if ((attach = name_attach(NULL, ATTACH_POINT,NAME_FLAG_ATTACH_GLOBAL )) == NULL) {
return EXIT_FAILURE;
}

rcvid = MsgReceive(attach->chid, &msg, sizeof(msg), NULL);

printf(“the message recieved is %d\n”,msg);

}

#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <sys/dispatch.h>

#define ATTACH_POINT “myname”

int main() {
int msg=123456;
int fd;

if ((fd = name_open(ATTACH_POINT, NAME_FLAG_ATTACH_GLOBAL)) == -1) {
    return EXIT_FAILURE;
}

MsgSend(fd, &msg, sizeof(msg), NULL, 0);

name_close(fd);
return EXIT_SUCCESS;

}

the client and server are run on different nodes…

SERVER:gns -s

CLIENT:gns -c[nodename]

problem:

1.attachpoint is created,but in form of a folder,not a file.A file is created in this folder.So client is unable to find the attachpoint
2.Server machine gets crashed sometimes.
3.If above two scenarios work fine,then data recieved on the server is 13138 instead of 123456.

Hi guys,

I had run a similar piece of code a while back. Only, like traditional servers, I kept the server side program in an infinite while loop for listening and initially, kept only one MsgSend on the client side. These programs were run on seperate QNX machines connected over a switch. What I observed was that on the server side, I got 3 messages. The data that I was sending was the connection id itself, which I think was getting printed the first time (it was printing ‘4’), and for the next two times, it was printing ‘0’.

Could this be caused due to the server not handling the _IO_CONNECT message?

Yes, read the documentation on name_* they are very clear about the requirement to handle these messages.

@mario: I just checked that out… The example program does handle IO_CONNECT msg. Thanks for the pointer.

-SM

I’ve posted examples of doing this before but here’s a cut down version:

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

    int myData;
};

// On the server side

while(1)
{
    if ((mRecvId = MsgReceive_r(mChannelId, &msg, sizeof(Message), NULL)) < 0)
    {
        printf("Error %s while trying to receive a message over connection %d on channel %d", strerror(abs(mRecvId)), mConnectId, mChannelId);
    }
    else
    {
        // Determine if we received a message or timer pulse
        if (mRecvId == 0)
        {
            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);
                    printf("Remote side %d disconnected from server", msg.timerPulse.scoid);
                    break;
                case _PULSE_CODE_UNBLOCK:
                     // Sender hit by a signal so release them to process it
                     Message emptyReply;
                     MsgReply_r(mRecvId, 0, emptyReply, sizeof(Message));
                     printf("Remote side hit by signal. Release them to process it");
                    break;
                case _PULSE_CODE_THREADDEATH:
                case _PULSE_CODE_COIDDEATH:
                     // Remote side died/exited!
                     printf("Remote side has unexpectedly died/exited while waiting for a message from them");
                     break;
                default:
                    // Timer pulse received. Do timer handling code here
	    break;
              }
        }
        else
        {
            // Reply to a name_open() call (this is for servers)
            if (msg.timerPulse.type == _IO_CONNECT)
            {
                MsgReply_r(mRecvId, EOK, NULL, 0);
                printf("Remote side %d connected to server", mRecvId);
            }
            else
            {
                // Reply now to unblock client immediately or do processing of message data then reply.
                printf("Data received is %d", msg.myData);
             }
        }
    }
}

Tim