Question

My server and client structures are as follows:

 struct server
{
  long msgtype;
  char find[20];

};
struct client
{ 
    long msgtype;
    char text[200];
};

I send a message from client program to the common message queue using msgsnd() function. I am facing difficulty in understanding this statement

If msgtyp is greater than zero, the first message of **type** msgtyp is received.

Does the type mean that when we use msgrcv() function the message received will be of type long (in this case). If so how is it possible to receive a structure in long?

Was it helpful?

Solution

The argument msgp [of the msgrcv() function] points to a user-defined buffer that must contain first a field of type 'long int' that will specify the type of the message, and then a data portion that will hold the data bytes of the message.

(Type 'long' is the same as type 'long int')

The 'msgtype' field is used to identify the message structure. The 'msgtype' field is followed by a user-defined data payload.

In your example, you would assign a number to represent the server structure (perhaps '1'), and another number to represent the client structure (perhaps '2').

When a message of type 'server' (or '1') is sent, by one endpoint, it will be received by another endpoint; and the 'server' message structure identified by the value in msgtype ('1').

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top