Exemplo n.º 1
0
        public void Start()
        {
            Console.WriteLine("Магазин создан. Pipe: {0}.", PipeName);

            while (true)
            {
                pipeServer = CreatePipeServer();
                pipeServer.WaitForConnection();
                try
                {
                    int userId = pipeServer.ReadByte();
                    var command = (Request)pipeServer.ReadByte();
                    if (userId == 0)
                    {
                        id += 1;
                        pipeServer.WriteByte((byte)id);
                        userId = id;
                    }
                    else
                    {
                        pipeServer.WriteByte((byte)userId);
                    }

                    switch (command)
                    {
                        case Request.GoSection:
                            HandleGoSection(userId);
                            break;
                        case Request.LeftSection:
                            HandleLeftSection(userId);
                            break;
                        case Request.IsVendorVacant:
                            HandleIsVendorVacant(userId);
                            break;
                        case Request.NewVendor:
                            HandleNewVendor(userId);
                            break;
                        case Request.NewBuyer:
                            HandleNewBuyer(userId);
                            break;
                        default:
                            Console.WriteLine("Неизвестная команда");
                            break;
                    }
                    pipeServer.WaitForPipeDrain();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }
Exemplo n.º 2
0
        private static int PingPong_OtherProcess(string inName, string outName)
        {
            // Create pipes with the supplied names
            using (var inbound = new NamedPipeClientStream(".", inName, PipeDirection.In))
            using (var outbound = new NamedPipeServerStream(outName, PipeDirection.Out))
            {
                // Wait for the connections to be established
                Task.WaitAll(inbound.ConnectAsync(), outbound.WaitForConnectionAsync());

                // Repeatedly read then write bytes from and to the other process
                for (int i = 0; i < 10; i++)
                {
                    int b = inbound.ReadByte();
                    outbound.WriteByte((byte)b);
                }
            }
            return SuccessExitCode;
        }
Exemplo n.º 3
0
        public void PingPong()
        {
            // Create names for two pipes
            string outName = Guid.NewGuid().ToString("N");
            string inName = Guid.NewGuid().ToString("N");

            // Create the two named pipes, one for each direction, then create
            // another process with which to communicate
            using (var outbound = new NamedPipeServerStream(outName, PipeDirection.Out))
            using (var inbound = new NamedPipeClientStream(".", inName, PipeDirection.In))
            using (var remote = RemoteInvoke(PingPong_OtherProcess, outName, inName))
            {
                // Wait for both pipes to be connected
                Task.WaitAll(outbound.WaitForConnectionAsync(), inbound.ConnectAsync());

                // Repeatedly write then read a byte to and from the other process
                for (byte i = 0; i < 10; i++)
                {
                    outbound.WriteByte(i);
                    int received = inbound.ReadByte();
                    Assert.Equal(i, received);
                }
            }
        }
Exemplo n.º 4
0
 private void Server()
 {
     using (var s = new NamedPipeServerStream("pipedream"))
     {
         s.WaitForConnection();
         byte b = 0x1;
         while (true)
         {
             s.WriteByte(b++);
             Thread.Sleep(10);
         }
     }
 }