Hi,
I'm trying to write a program using named pipes, and I'm having trouble opening it. In another program I call this line:

mkfifo("./fife", 0777);

So my named pipe exists and I see it in my list of files. Then I run the program I included below, but I can not get past the open call. Any help would be appreciated for I can not find a lot of resources on this subject.

#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <iostream>

#define MSGSIZE 14

void main() {
  char *message = "Hello, world!";

  int fd;
  fd = open("fife", O_WRONLY);
 // Can not get past this point!

  cout << "fd: " << fd << endl;

  if (write(fd, message, MSGSIZE) < 0)
    cout << "error writing" << endl;

  close(fd);
}

I found out the problem. It waits because it wants another program to handle the other end of the pipe.

I fixed my codes up and I wrote a script like this to fix the problem:

#!/bin/bash
echo "Running clients..."
./client &
./client &

echo "Running server..."
./server
# The & runs the program in the background, so you can run another program, playing client and server in the same console

can you post the client program (reading program) too?

a) you're too late - by at least a year, check the dates.
b) try programming something for yourself.
c) start your own thread when you've got something to show.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.