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

  • Home
  • SEARCH
  • 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 7410905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:18:17+00:00 2026-05-29T06:18:17+00:00

I have 2 applications communicating using named pipes. Main program calls client program and

  • 0

I have 2 applications communicating using named pipes.

Main program calls client program and creates pipe server to communicate with it. The client program creates pipe client. Main program can send any messages to client program and they should be handled on client side in some way. When client program is exiting, it is sending any message to main program and it means that server pipe should be closed.

I had no problem implementing the first part (sending messages from server to client) using server with PipeDirection.Out and client with PipeDirection.In. But when I tried to modify the code so that server and client are both having PipeDirection.InOut (to be able to send message from client to server), the code stopped working. The program hangs when I do writer.Flush (on server side) or writer.WriteByte (on client side). The places when it hangs now are marked as [HANGS HERE].

Server is created like this:

public static void CreatePipeServerStream()    
{
    var namedPipeServerStream = new NamedPipeServerStream("somename", PipeDirection.InOut);
    namedPipeServerStream.WaitForConnection();

    // This thread is wating for message from client
    ThreadStart starter = () => WaitForSignalFromClient(namedPipeServerStream);
    new Thread(starter).Start();
}

private static void WaitForSignalFromClient(NamedPipeServerStream namedPipeServerStream)
{
    if (namedPipeServerStream.IsConnected)
    {
        namedPipeServerStream.ReadByte();
        // we'll get here after something is read
        // and if we got here, we should close the server pipe
        // now I can get here only if I shut down the client program using Task manager
        namedPipeServerStream.Close();
    }
}

The procedure sending message to client is doing this (used to work when server had pipe direction == Out and client had pipe direction == In):

public static void SendMessageUsingPipe(NamedPipeServerStream namedPipeServerStream)
{
    if (namedPipeServerStream.IsConnected)
    {
        var sw = new StreamWriter(namedPipeServerStream);
        sw.WriteLine("smth");
        // [HANGS HERE]
        sw.Flush();
    }
}

On the client side, this code is running in separate thread:

private void WaitServerCommands()
{
    _pipe = new NamedPipeClientStream(".", "somename", PipeDirection.InOut);
    using (var rdr = new StreamReader(_pipe))
    {
        while (true)
        {
            if (!_pipe.IsConnected)
            {
                _pipe.Connect();
            }
            rdr.ReadLine();
            // I don't care what was sent by server, I just need to know that something was sent
            Invoke(_handleCommand);
        }
    }
}

The code that is supposed to send message to server:

private void ClosePipes()
{
    if (_pipe != null && _pipe.IsConnected)
    {
        // [HANGS HERE]
        _pipe.WriteByte(113);
        _pipe.WaitForPipeDrain();
        _pipe.Close();
    }
}

Any idea what is wrong with the code? Or maybe I miss something fundamental?

The actual problem is that I need to know on server side that the client has disconnected. Maybe it can be achieved in some other way?

  • 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-29T06:18:18+00:00Added an answer on May 29, 2026 at 6:18 am

    I don’t think your setting the pipserver up correctly.

    namedPipeServerStream.WaitForConnection() will block the current thread until a client connects.

    When a client does connect you then read a byte from the client, at the same time you have the client reading a line from the server.

    namedPipeServerStream.ReadByte();
    rdr.ReadLine();
    

    I’m guessing they are in stalemate waiting for one of them to send some info across.

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

Sidebar

Related Questions

I have a simple TCP socket client and server application. They are communicating using
I have created WCF client/ server applications using calculator demo as mentioned in http://msdn.microsoft.com/en-us/library/ms734712.aspx
I have a client-server application written in Java using CORBA for the communication. The
I have a Silverlight application on the client communicating with the server side through
I have client/server applications and a very simple protocol for communication. More precisely, it's
I am using Named Pipes to transfer data from a client (C++) to a
I have two applications communicating via RMI, a slave server (of which there will
I have a Silverlight application communicating with the server side through WCF services. Initially
I have a Windows server application, implemented in C++ using the Win32 API, that
We have a WCF (Windows Communication Foundation) client and service application. We're using Windows

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.