Sponsored Content
Full Discussion: Message Queue Problem
Top Forums Programming Message Queue Problem Post 75468 by SaTYR on Sunday 19th of June 2005 05:27:37 AM
Old 06-19-2005
Power

Hi there, i wrote the code but i forgot to update my message..
Now i'm uploading my code...
While you are compiling, make

client.txt->client.c
server.txt->server.c
local.txt->local.h

probably you need to compile server.c like
gcc -o server server.c -lpthread
for including thread objects.

This is the default structural approach of message queues Perderabo

Code:
struct  mymsg {
        long  mtype;     /* message type */
        char  mtext[1];  /* message text */
}

but the main idea is the first long type describes the type of the message and the char pointer shows the starting address of other things in the structure...

if you send a custom structure and receive it with the same structure, you got the message. (Mainly the flexibility of the message queue comes here, you can send and receive your custom structure.)

Code:
typedef struct message{
	long mtype;
	int receiver_id;
	int sender_id;
	char type;
	int length;
	
	char data[MAXDATA];
}msg_tb;

Here, under the 'long mtype' understood with a char pointer by the message queue, because at the message queue process it only need the starting address of the message (size of the message gave at the msgsnd command) so that you can send whatever structure you want with the message queue.

Thats it. Smilie
This User Gave Thanks to SaTYR For This Post:
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Unix message Queue

Hi, I am working closly with unix message queues i have encountered the following - after creating the Q and start working with it (pushing & pulling) i receive the following stange parameters on the q's - STIME=no_entry Qnum=0 CBYTES=4140 when this happens, the Q is disabled (meaning i... (3 Replies)
Discussion started by: kel
3 Replies

2. UNIX for Dummies Questions & Answers

Cron message queue problem

I have a problem with running jobs out of cron on Solaris 8. Initially when one of the users on the box (other than root) attempted to save the crontab after modification by using "crontab -e", the message "Crontab: cannot open the crontab file in the crontab directory" was given. I then... (7 Replies)
Discussion started by: mattd
7 Replies

3. Programming

a message queue question..

Hi there: Thanks first. When I use a message queue amony severl processes, will I have to synchronize the queue? I don't think I would have to because a message queue is implemented in a link listed. Correct me If I am wrong... (0 Replies)
Discussion started by: yanhu
0 Replies

4. Programming

Message Queue Problem Again..

Is there any way one can delete , say , a particular message from a message queue on system V? (2 Replies)
Discussion started by: satansfury
2 Replies

5. IP Networking

message queue problem

I am sending and retriving the message to the queue the problem is after retrieving the message can i see what is there in my message queue. (actually in my application i am encountring some garbage value) so i want to retieve this garbage value and also want to know its size how... (0 Replies)
Discussion started by: ramneek
0 Replies

6. Programming

Message Queue with fork() help

hi all... ive been trying this program where i spawn 4 threads... and i am trying to use message queue to send msgs from 3 of the threads to the parent thread... but it doent seem to be working... ive almost pulled out my hair tryin to fix the prob :confused: another wierd thing... (1 Reply)
Discussion started by: strider
1 Replies

7. Programming

message queue

Hello, i need to write a message queue "chat server", that should work only localy. Can anyone please help me with some ideas and peshaps code. I'm studying the UNIX IPC mechanisms right now. So far, i understand how it works but i still cannot get an idea how to write a chat programm... ... (2 Replies)
Discussion started by: etenv
2 Replies

8. Programming

[C]Problem removing a message queue

Hi!! This code works if I don't remove the message queue. In A.c I create 3 processes that send a message in a message queue. in B.c other 3 processes receive 1 message for each (the messages sent from A), change the value of "dato" and put again the message in the queue. The processes in A.c... (0 Replies)
Discussion started by: Sentinella
0 Replies

9. Programming

How to limit max no of message in a posix message queue

Hii can anyone pls tell how to limit the max no of message in a posix message queue. I have made changes in proc/sys/fs/mqueue/msg_max But still whenever i try to read the value of max. message in the queue using attr.mq_curmsgs (where struct mq_attr attr) its giving the default value as 10.... (0 Replies)
Discussion started by: mohit3884
0 Replies

10. Programming

UNIX Message Queue

Hello !!!!! I have a simple question but i can't find the answer anywhere hope to meet it here. Why it is a bad idea to pass pointers through message queues ? Most structs i see all of their char types are arrays... Is it becase having pointers means we could possibily send wrong bytes ? For... (2 Replies)
Discussion started by: qlyine
2 Replies
MSGSND(2)						      BSD System Calls Manual							 MSGSND(2)

NAME
msgsnd -- send a message to a message queue LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <sys/msg.h> int msgsnd(int msqid, const void *msgp, size_t msgsz, int msgflg); DESCRIPTION
The msgsnd() function sends a message from the message queue specified in msqid. The msgp argument is a pointer to a user-defined structure containing the message. This structure must contain a first field of type long that will indicate the user-defined type of the message. The remaining fields will contain the contents of the message. The following is an example of what this user-defined structure might look like: struct mymsg { long mtype; /* message type */ char mtext[1]; /* body of message */ }; The mtype field is an integer greater than 0 that can be used for selecting messages (see msgrcv(2)). The mtext field is an array of bytes, with size up to the system limit MSGMAX. If the number of bytes already on the message queue plus msgsz is greater than the maximum number of bytes in the message queue (msg_qbytes, see msgctl(2)), or if the number of messages on all queues system-wide is already equal to the system limit, msgflg determines the action of msgsnd(). If msgflg has IPC_NOWAIT mask set in it, the call will return immediately. If msgflg does not have IPC_NOWAIT set in it, the call will block until: o The condition which caused the call to block no longer exists. The message was sent. o The message queue is removed, in which case -1 will be returned and errno set to EINVAL. o The caller catches a signal. The call returns with errno set to EINTR. After a successful call, the data structure associated with the message queue is updated in the following way: o msg_qnum is incremented by 1. o msg_lspid is set to the pid of the calling process. o msg_stime is set to the current time. RETURN VALUES
Upon successful completion, 0 is returned. Otherwise, -1 is returned and errno is set to indicate the error. ERRORS
msgsnd() will fail if: [EACCES] The calling process does not have write access to the message queue. [EAGAIN] There was no space for this message either on the queue or in the whole system, and IPC_NOWAIT was set in msgflg. [EFAULT] msgp points to an invalid address. [EINTR] The system call was interrupted by the delivery of a signal. [EINVAL] The msqid argument is not a valid message queue identifier, or the value of mtype is less than 1. The message queue was removed while msgsnd() was waiting for a resource to become available in order to deliver the mes- sage. The msgsz argument is greater than msg_qbytes or SSIZE_MAX. SEE ALSO
msgctl(2), msgget(2), msgrcv(2) STANDARDS
The msgsnd system call conforms to X/Open System Interfaces and Headers Issue 5 (``XSH5'') and IEEE Std 1003.1-2001 (``POSIX.1''). HISTORY
Message queues appeared in the first release of AT&T System V UNIX. BSD
April 30, 2010 BSD
All times are GMT -4. The time now is 09:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy