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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T18:38:16+00:00 2026-05-11T18:38:16+00:00

I have two .NET applications that talk to each other over a named pipe.

  • 0

I have two .NET applications that talk to each other over a named pipe. Everything is great the first time through, but after the first message is sent, and the server is going to listen again, the WaitForConnection() method throws a System.IO.Exception with message Pipe is broken.
Why am I getting this exception here? This is my first time working with pipes, but a similar pattern has worked for me in the past with sockets.

Code ahoy!
Server:

using System.IO.Pipes;

static void main()
{
    var pipe = new NamedPipeServerStream("pipename", PipeDirection.In);
    while (true)
    {
        pipe.Listen();
        string str = new StreamReader(pipe).ReadToEnd();
        Console.Write("{0}", str);
    }
}

Client:

public void sendDownPipe(string str)
{
    using (var pipe = new NamedPipeClientStream(".", "pipename", PipeDirection.Out))
    {
        using (var stream = new StreamWriter(pipe))
        {
            stream.Write(str);
        }
    }
}

The first call to sendDownPipe gets the server to print the message I send just fine, but when it loops back up to listen again, it poops.

  • 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-11T18:38:16+00:00Added an answer on May 11, 2026 at 6:38 pm

    I’ll post my code that seems to work – I was curious since I never did anything with pipes. I didn’t find the class you name for the server-side in the relevant namespace, so here’s the code based on the NamedPipeServerStream. The callback stuff is just because I couldn’t be bothered with two projects.

    NamedPipeServerStream s = new NamedPipeServerStream("p", PipeDirection.In);
    Action<NamedPipeServerStream> a = callBack;
    a.BeginInvoke(s, ar => { }, null);
    ...
    private void callBack(NamedPipeServerStream pipe)
    {
      while (true)
      {
        pipe.WaitForConnection();
        StreamReader sr = new StreamReader(pipe);
        Console.WriteLine(sr.ReadToEnd());
        pipe.Disconnect();
      }
    }
    

    And the client does this:

    using (var pipe = new NamedPipeClientStream(".", "p", PipeDirection.Out))
    using (var stream = new StreamWriter(pipe))
    {
      pipe.Connect();
      stream.Write("Hello");
    }
    

    I can repeat above block multiple times with the server running, no prob.

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

Sidebar

Related Questions

We have two thick-client .NET applications that need to send messages to each other
First, a little background. I have two ASP.NET web applications that use SQLServer session
I have two .net applications that run on the same machine. The first application
I have two Visual Studio vb.NET applications. Previously, I have published each application separately
Let's say that I have two .Net applications running on a single machine. Both
I have two small VB.NET applications that connect to the same Oracle database. One
I have an ASP.NET MVC3 application that I have built and it has two
I have application in VB.net that have two different form (Form1 and Form2). Now
I have two ASP.NET MVC web applications. One of them logs unhandled exceptions to
I have been experimenting with sending messages from two .NET Windows Forms applications using

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.