Design a program using ordinary pipes in which one process sends a string message to a second process, and the second process reverses the case of each character in the message and sends it back to the first process. for example, if the first process sends the message hi there, the second process will return hi there. this will require using two pipes, one for sending the original message from the first to the second process and the other for sending the modified message from the second to the first process. you can write this program using either unix or windows pipes.

Respuesta :

tonb

Here's a solution in C#. Create two console applications, one for the client and one for the server. In the server, put this:

           Console.WriteLine("Listening to pipe...");

           var server = new NamedPipeServerStream("BrainlyPipe");

           server.WaitForConnection();

           var reader = new StreamReader(server);

           var writer = new StreamWriter(server);

           while (true)

           {

               var line = reader.ReadLine();

               if (!server.IsConnected) break;

               Console.WriteLine("Received: " + line);

               writer.WriteLine(ChangeCase(line));

               writer.Flush();

           }

To change case, add this function:

       public static string ChangeCase( string s)

       {

           var sb = new StringBuilder();

           foreach(char c in s)

               sb.Append(char.IsUpper(c) ? char.ToLower(c) : char.ToUpper(c));

           return sb.ToString();

       }

In the client, put this:

           var client = new NamedPipeClientStream("BrainlyPipe");

           client.Connect();

           var reader = new StreamReader(client);

           var writer = new StreamWriter(client);

           writer.WriteLine("Brainly question 13806153 demo");

           writer.Flush();

           Console.WriteLine(reader.ReadLine());

           Console.ReadLine();