Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8964219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:32:17+00:00 2026-06-15T16:32:17+00:00

I found on stackoverflow client-server code (using named pipes) and I modified it to

  • 0

I found on stackoverflow client-server code (using named pipes) and I modified it to let client send messages in while loop. Althought I get messages from server, I get “Illegal seek” on read/write and Im not sure if its an serious error, if something is really bad here?

server.cpp

#include <fcntl.h>
#include <stdio.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>

int main()
{
   int client_to_server;
   char *myfifo = "/tmp/client_to_server_fifo";

   int server_to_client;
   char *myfifo2 = "/tmp/server_to_client_fifo";

   char buf[BUFSIZ];

   /* create the FIFO (named pipe) */
   mkfifo(myfifo, 0666);
   mkfifo(myfifo2, 0666);

   /* open, read, and display the message from the FIFO */
   client_to_server = open(myfifo, O_RDONLY);
   server_to_client = open(myfifo2, O_WRONLY);

   printf("Server ON.\n");

   while (1)
   {
      read(client_to_server, buf, BUFSIZ);

      if (strcmp("exit",buf)==0)
      {
         printf("Server OFF.\n");
         break;
      }

      else if (strcmp("",buf)!=0)
      {
         printf("Received: %s\n", buf);
         printf("Sending back...\n");
         write(server_to_client,buf,BUFSIZ);
      }

      /* clean buf from any data */
      memset(buf, 0, sizeof(buf));
   }

   close(client_to_server);
   close(server_to_client);

   unlink(myfifo);
   unlink(myfifo2);
   return 0;
}

client.cpp

#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
   int client_to_server;
   char *myfifo = "/tmp/client_to_server_fifo";

   int server_to_client;
   char *myfifo2 = "/tmp/server_to_client_fifo";

   char str[BUFSIZ];


   //printf("Input message to serwer: ");
   //scanf("%s", str);


   /* write str to the FIFO */
   client_to_server = open(myfifo, O_WRONLY);
   server_to_client = open(myfifo2, O_RDONLY);

while(true)
{

   printf("> "); 
   scanf("%s", str);
   write(client_to_server, str, sizeof(str));

   perror("Write:"); //Very crude error check

   read(server_to_client,str,sizeof(str));

   perror("Read:"); // Very crude error check

   printf("From  server: %s\n",str);
}
   close(client_to_server);
   close(server_to_client);

   /* remove the FIFO */

   return 0;
}

Example output:

client :

> hello, server!
Write:: Success
Read:: Illegal seek
From  server: hello,
Write:: Illegal seek
Read:: Illegal seek
> From  server: server!
> its client here!
Write:: Illegal seek
Read:: Illegal seek
From  server: its
Write:: Illegal seek
Read:: Illegal seek
> From  server: client
Write:: Illegal seek
Read:: Illegal seek
> From  server: here!
> > hello, server!
// and so on ...

server :

Server ON.
Received: hello,
Sending back...
Received: server!
Sending back...
Received: its
Sending back...
Received: client
Sending back...
Received: here!
Sending back...
Received: >
Sending back...
Received: hello,
Sending back...
Received: server!
Sending back...
Received: Write::
Sending back...
Received: Success
Sending back...
Received: Read::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: From
Sending back...
Received: server:
Sending back...
Received: hello,
Sending back...
Received: Write::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: Read::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: >
Sending back...
Received: From
Sending back...
Received: server:
Sending back...
Received: server!
Sending back...
Received: >
Sending back...
Received: its
Sending back...
Received: client
Sending back...
Received: here!
Sending back...
Received: Write::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: Read::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: From
Sending back...
Received: server:
Sending back...
Received: its
Sending back...
Received: Write::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: Read::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: >
Sending back...
Received: From
Sending back...
Received: server:
Sending back...
Received: client
Sending back...
Received: Write::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: Read::
Sending back...
Received: Illegal
Sending back...
Received: seek
Sending back...
Received: >
Sending back...
Received: From
Sending back...
Received: server:
Sending back...
Received: here!
Sending back...
Received: >
Sending back...
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:32:18+00:00Added an answer on June 15, 2026 at 4:32 pm

    Don’t call perror if there was no error.

    You need to check if the previous function call failed before you can call perror or you’ll get meaningless error messages when no error actually happened. Functions (usually) aren’t required to set errno to anything particular if they don’t fail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this piece of code (found on stackoverflow) to generate an OrderBy static
I currently have this useful code that I found elsewhere on StackOverflow: form.DrawToBitmap(bmp, new
I'm using some Javascript I found from a post on StackOverflow. When I start
When client request for a file, I use this code to send it: public
Code can be found here: http://www.myhorizon.ca/client_central/sortable_test.php Hello folks of Stackoverflow, I have a list
I found different Stackoverflow-Questons, but I don't see what I'm doing wrong in my
I've tried quite some fixes i found on stackoverflow and elsewhere but I couldn't
I looked through Stackoverflow and found almost identical question here . It was asked
I found a lot of helpful information on stackoverflow, but a tiny bit is
I found this answer to this question https://stackoverflow.com/a/7244888/1473523 , but in my situation am

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.