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 8447603
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:13:12+00:00 2026-06-10T10:13:12+00:00

I’am having some trouble to make a Duplex communication between a C# server and

  • 0

I’am having some trouble to make a Duplex communication between a C# server and a C++ work:

The objective is to create the pipe, read something from the client and write something back.
Everything is working fine if i’m just reading from the client or just writing to the client but I can’t do both one after the other!

Here’s my C# server:

// Create a name pipe
 using (NamedPipeServerStream pipeStream = new NamedPipeServerStream("TestPipe"))
 {
   Console.WriteLine("[Server] Pipe created {0}", pipeStream.GetHashCode());

   // Wait for a connection
   pipeStream.WaitForConnection();
   Console.WriteLine("[Server] Pipe connection established");

   //Reading Part
   using (StreamReader sr = new StreamReader(pipeStream))
   {
      string temp;
      while ((temp = sr.ReadLine()) != null)
      {
         Console.WriteLine("{0}: {1}", DateTime.Now, temp);
       }
     }

     //Writing Part
     using (StreamWriter sw = new StreamWriter(pipeStream))
     {
        sw.AutoFlush = true;
        String st = "send Back\0";
        sw.WriteLine(st);
     }
 }

And Here is the C++ client:

HANDLE hFile;
BOOL flg;
DWORD dwWrite;
char szPipeUpdate[200];
hFile = CreateFile(L"\\\\.\\pipe\\TestPipe", GENERIC_WRITE|GENERIC_READ,
                           0, NULL, OPEN_EXISTING,
                           0, NULL);


 strcpy(szPipeUpdate,"Sending some data from client to server!");
 if(hFile == INVALID_HANDLE_VALUE)
  { 
        DWORD dw = GetLastError();
        printf("CreateFile failed for Named Pipe client\n:" );
  }
  else
  {
      flg = WriteFile(hFile, szPipeUpdate, strlen(szPipeUpdate), &dwWrite, NULL);
      if (FALSE == flg)
      {
         printf("WriteFile failed for Named Pipe client\n");
      }
      else
      {
         printf("WriteFile succeeded for Named Pipe client\n");
      }
  }

  printf("Let's read!\n");
  //Read the datas sent by the server
  BOOL fFinishRead = FALSE;
  do
    {
        char chResponse[200];
        DWORD cbResponse, cbRead;
        cbResponse = sizeof(chResponse);

        fFinishRead = ReadFile(
            hFile,                  // Handle of the pipe
            chResponse,             // Buffer to receive the reply
            cbResponse,             // Size of buffer in bytes
            &cbRead,                // Number of bytes read 
            NULL                    // Not overlapped 
            );

        if (!fFinishRead && ERROR_MORE_DATA != GetLastError())
        {
            DWORD  dwError = GetLastError();
            wprintf(L"ReadFile from pipe failed w/err 0x%08lx\n", dwError);
            break;
        }
        std::cout << chResponse;

    } while (!fFinishRead); // Repeat loop if ERROR_MORE_DATA
 CloseHandle(hFile);
  • 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-10T10:13:13+00:00Added an answer on June 10, 2026 at 10:13 am

    With the Server & Client NamedPipeStreams you need to make sure at least one end of the connection is attempting to read at all times, otherwise writes will fail. I’d guess it’s a timing issue between your client & server around whichever is listening/writing. Here’s a quick blog post explaining this behavior as well.

    I’d recomend using two streams on the client & server, both reading/writing from the same pipe.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display

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.