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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:55:31+00:00 2026-05-31T07:55:31+00:00

I am trying to get started with working with named pipes as I will

  • 0

I am trying to get started with working with named pipes as I will need to use them for a project of mine in the future.

At the moment I have a C++ server which waits until a client connects and sends over a test message. I roughly followed this tutorial to get started. The relevant code is below:

    #define MESSAGE L"TestMessage"

HANDLE hnamedPipe = INVALID_HANDLE_VALUE;

hnamedPipe = CreateNamedPipe(
    L"\\\\.\\pipe\\testpipe",
    PIPE_ACCESS_DUPLEX,
    PIPE_TYPE_MESSAGE|
    PIPE_READMODE_MESSAGE|
    PIPE_WAIT,
    PIPE_UNLIMITED_INSTANCES,
    1024,
    1024,
    NMPWAIT_USE_DEFAULT_WAIT,
    NULL);

if(hnamedPipe == INVALID_HANDLE_VALUE)
{
        cout << "Failed" << endl;
}

while(true)
{
    cout<< "Waiting for client"<< endl;

    if(!ConnectNamedPipe(hnamedPipe,NULL))
    {
        if(ERROR_PIPE_CONNECTED != GetLastError())
        {
        cout << "FAIL"<< endl;
        }
    }

    cout<<"Connected!"<<endl;

    //Send over the message
    wchar_t chResponse[] = MESSAGE;
    DWORD cbResponse,cbWritten;
    cbResponse = sizeof(chResponse);

    if(!WriteFile(
    hnamedPipe,
    chResponse,
    cbResponse,
    &cbWritten,
    NULL))
    {
        wprintf(L"failiure w/err 0x%08lx\n",GetLastError);
    }
    cout<<"Sent bytes :)" << endl;
}

The client code (C#) is below:

        using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", "testpipe", PipeDirection.InOut))
        {
            while (true)
            {
                Console.WriteLine("Connecting to server...");
                pipeClient.Connect();

                Console.WriteLine("Connected :)");
                Console.WriteLine(pipeClient.ReadByte());
                pipeClient.Close();
                Console.WriteLine("Closed");
            }

        }

At the moment I have got the client to connect successfully to the server and it prints out the first byte. I want to know how to do 2 things:

  1. Read the entire message – I tried using StreamReader over the pipeClient to read the message but it hangs on ReadLine() indefinitely.

  2. Continuously send over messages – I want the server to send message after message to the client which will read them in one at a time and print them out. I am a bit clueless about IPC so at first I tried to make the client disconnect and reconnect to the server in the while(true) loop whilst the server is in a while true loop which at the top always waits for a new client connection before sending another message. My attempt at this is in the code above.

Any help with this would be greatly appreciated. Eventually the aim is to be sending over images from the server to the client. The client would then print them out to the screen in real-time. I wanted to get this working with simple string messages before I tried the image data.

EDIT:

Eventually I want to be able to send a message from the client to the server indicating it wants to get the latest image frame, the server will then send over the latest frame which the client will then display on screen. So the flow is:

  1. Client -> Server : indicator that client wants the latest frame info. (Something simple, maybe an unsigned int with the value 1)
  2. Server -> Client : Latest frame info. (640×480 image stored in a byte array with RGB byte values)
  3. Client : Display the frame on the display.
  • 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-05-31T07:55:33+00:00Added an answer on May 31, 2026 at 7:55 am

    ReadLine hangs because it is waiting for a newline, which your test message doesn’t include.

    If you want the server to send messages continuously just put a loop round the WriteFile call. You don’t need to connect more than once. Similarly in the client, put the loop around ReadLine.

    If each message consists of text terminated by a newline then that should suffice, but if you really want the pipe client to work in message mode you need to call:

    pipeClient.ReadMode = PipeTransmissionMode.Message;
    

    However, I doubt this would interact well with a StreamReader. Instead, you should read single messages using pipeClient.Read.

    Update

    To answer your new question:

    On the server, once the client has connected enter a loop in which:

    • The server does a read from the client. This will block until the client requests a frame.
    • The server sends a frame.

    On the client, once it has connected to the server enter a loop in which:

    • The client sends a “please send a frame” message.
    • The client does a read from the server to get the frame.
    • The client displays the frame.

    I wouldn’t use a message mode pipe. If the frames are fixed in size then the client knows how much data to read from the server. Otherwise, precede the frame with a uint containing its length.

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

Sidebar

Related Questions

I've been trying to get started with unit-testing while working on a little cli
I'm working on a script to get started in PowerShell . I'm trying to
I am trying to get started with scons . I have Python 3.0.1 and
i'm trying to get started with silverlight 2. i have a weird bug. every
I'm trying to get the GKTank example working with 2 iPhones. Both have bluetooth
I have been trying to write a simple mention grabber to get started with
I'm trying to get fancybox (technically fancybox-rails) working in Rails 3.1. I started with
I am trying to get started developing using the .NET Micro Framework but appear
I'm trying to get started with USSD . I'm familiar with other forms of
I'm trying to get started with unit testing in Python and I was wondering

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.