LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 02-03-2002, 05:45 AM   #1
raven
Member
 
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297

Rep: Reputation: 31
ipc problem


hello

i have a problem using ipc-message-queues.

if i put this into my code:

if ((msgrcv(msgid,message,60,0,MSG_NOERROR))<0)

then reading of the message causes the program to exit (error message: bad address)

does the message has to have a special type? the client sends a message with type:

char *message;

ist this OK?

then what is the problem?

i can initialise the queue, no problems there, everything seems to work, the client sends the message coorectly (or at least it seems so), but the server cannot read the message from the queue.

any help is welcome

raven
 
Old 02-03-2002, 02:12 PM   #2
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
I'm not sure exactly what your code looks like, so I'm unable to give you a better clue of what is wrong. I can provide you with a simple example that works:

Hope this helps.

Code:
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/msg.h>

struct message
{
   long message_type;
   char message_data[256];
};

main()
{
   int msgid;
   struct message msg;
   struct message msg_in;

   // create message queue
   msgid = msgget( 123, IPC_CREAT | 0644 );
   if ( msgid == -1 )
   {
      printf("Unable to get message queue\n");
      exit(-1);
   }  // end if

   msg.message_type = 1;
   strcpy( msg.message_data, "Hello there" );

   msgsnd( msgid, &msg, sizeof( msg ) - sizeof( long ), 0 );

   msgrcv( msgid, &msg_in, sizeof( msg_in ) - sizeof( long ), 1, 0 );

   printf( "Message is: [%s]\n", msg_in.message_data );

   // remove message queue
   msgctl( msgid, IPC_RMID, 0 );
}
 
Old 02-03-2002, 02:14 PM   #3
crabboy
Moderator
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,823

Rep: Reputation: 120Reputation: 120
I forgot to mention some commands that can be helpful when dealing with shared mem, semaphores and queues.
Code:
ipcs
ipcrm
 
Old 02-04-2002, 10:53 AM   #4
raven
Member
 
Registered: Dec 2001
Location: Basel, Switzerland
Distribution: ubuntu
Posts: 297

Original Poster
Rep: Reputation: 31
thank you it works now fine.

the problem was i sent a plaintext message to the server and no struct...

thanks anyway

raven
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is going on with IPC in linux? Hano Linux - General 8 12-05-2005 11:01 PM
IPC question... climbingmerlin Programming 4 11-03-2005 03:30 AM
IPC problem greghua Programming 2 08-19-2005 07:43 PM
about IPC iclinux Programming 1 01-14-2005 11:16 PM
Semaphores and IPC gsu_790 Programming 2 09-29-2004 09:29 AM


All times are GMT -5. The time now is 07:52 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration