I'm trying to write a client and server which are going to exchange data by using POSIX message queue. I tried to do it by looking at the examples I saw in the Internet and the documents of the course. But, I am stuck in. When I run it, I get "Too many open files" error. Here is my code:
Client:
int main( int argc, char *argv[]) {
//Open its queue, which is client queue
char cq_name[10];
sprintf( cq_name, "/cq%i", getpid());
printf( "Client Queue name: %s\n", cq_name);
mqd_t cq_id = mq_open( cq_name, O_CREAT | O_RDWR, 0666, NULL);
if( cq_id == -1) {
printf( "Error in cq: %s\n", strerror( errno));
return -1;
}
printf( "Name: %s\n", argv[1]);
//Connect to the server message queue
mqd_t sq_id = mq_open( argv[1], O_RDWR);
if( sq_id == -1) {
printf( "Error in sq: %s\n", strerror( errno));
return -1;
}
...
Server:
int main( int argc, char *argv[]) {
//The server message queue
struct mq_attr attr;
attr.mq_flags = 0;
attr.mq_curmsgs = 0;
printf( "Name: %s\n", argv[1]);
mqd_t id = mq_open( argv[1], O_CREAT | O_RDWR, 0666, NULL);
//Check the message queue
if( id == -1) {
printf( "Error: %s\n", strerror(errno));
}
printf( "Check Point 1 - %i\n", id);
...
Can you help me to figure out what the problem is. Thanks in advance..