当前位置: 首页>>代码示例>>C#>>正文


C# NamedPipeServerStream.ReadByte方法代码示例

本文整理汇总了C#中System.IO.Pipes.NamedPipeServerStream.ReadByte方法的典型用法代码示例。如果您正苦于以下问题:C# NamedPipeServerStream.ReadByte方法的具体用法?C# NamedPipeServerStream.ReadByte怎么用?C# NamedPipeServerStream.ReadByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.Pipes.NamedPipeServerStream的用法示例。


在下文中一共展示了NamedPipeServerStream.ReadByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

        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);
                }
            }
        }
开发者ID:REVcon,项目名称:PP,代码行数:52,代码来源:ShopServer.cs

示例2: NamedPipeWriteViaAsyncFileStream

        public async Task NamedPipeWriteViaAsyncFileStream(bool asyncWrites)
        {
            string name = Guid.NewGuid().ToString("N");
            using (var server = new NamedPipeServerStream(name, PipeDirection.In, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous))
            {
                Task serverTask = Task.Run(async () =>
                {
                    await server.WaitForConnectionAsync();
                    for (int i = 0; i < 6; i++)
                        Assert.Equal(i, server.ReadByte());
                });

                WaitNamedPipeW(@"\\.\pipe\" + name, -1);
                using (SafeFileHandle clientHandle = CreateFileW(@"\\.\pipe\" + name, GENERIC_WRITE, FileShare.None, IntPtr.Zero, FileMode.Open, (int)PipeOptions.Asynchronous, IntPtr.Zero))
                using (var client = new FileStream(clientHandle, FileAccess.Write, bufferSize: 3, isAsync: true))
                {
                    var data = new[] { new byte[] { 0, 1 }, new byte[] { 2, 3 }, new byte[] { 4, 5 } };
                    foreach (byte[] arr in data)
                    {
                        if (asyncWrites)
                            await client.WriteAsync(arr, 0, arr.Length);
                        else
                            client.Write(arr, 0, arr.Length);
                    }
                }

                await serverTask;
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:29,代码来源:Pipes.cs

示例3: Main

        static void Main(string[] args)
        {
            Console.Title = "Log - Trinix";

            if (!Directory.Exists("Logs"))
                Directory.CreateDirectory("Logs");

            Parser parser = null;
            while (true)
            {
                NamedPipeServerStream pipeServer = new NamedPipeServerStream("trinix");
                pipeServer.WaitForConnection();

                if (parser != null)
                    parser.Dispose();

              //  MemoryStream ms = new MemoryStream();
                //parser = new Parser();
               // parser.Parse(ms);
                StreamWriter log = new StreamWriter("Logs\\" + String.Format("{0:yyyy-MM-dd-HH-mm-ss}", DateTime.Now) + ".log");

                try
                {
                    while (pipeServer.IsConnected)
                    {
                        int v = pipeServer.ReadByte();

                        if (v == -1)
                            break;

                       // ms.WriteByte((byte)v);
                        Console.Write((char)v);
                        log.Write((char)v);
                    }

                    pipeServer.Close();
                    log.Close();
                }
                catch
                {
                }

                Console.Write(Environment.NewLine);
                Console.WriteLine("----------- Connection ended -----------");
                Console.Write(Environment.NewLine);
            }
        }
开发者ID:jamonahn,项目名称:Trinix,代码行数:47,代码来源:Program.cs

示例4: Start

        public void Start()
        {
            Console.WriteLine("Обед философов начался ! Всего {0} столовых приборов !", _forksCount);
            bool hasStarted = false;
            while (_connectedPhilosopherCount > 0 || !hasStarted)
            {
                _pipeServer = CreateServerPipe();
                _pipeServer.WaitForConnection();

                var request = (Request)_pipeServer.ReadByte();
                switch(request)
                {
                    case Request.GetPhilosopherPosition:
                        AssignPhilosopherPosition();
                        hasStarted = true;
                        break;
                    case Request.Eat:
                        Eat();
                        break;
                    case Request.Think:
                        Think();
                        break;
                    case Request.Rest:
                        Rest();
                        break;
                    case Request.TakeFork:
                        TakeFork();
                        break;
                    case Request.PutFork:
                        PutDownFork();
                        break;
                    default:
                        break;
                }
                _pipeServer.WaitForPipeDrain();
            }

            Console.WriteLine("Все ушли !");
            Console.ReadLine();
        }
开发者ID:RoadToExclusivity,项目名称:PP,代码行数:40,代码来源:LunchServer.cs

示例5: ReadFileName

 private static string ReadFileName(NamedPipeServerStream server)
 {
     char ch;
     var fileName = "";
     while ((ch = (char)server.ReadByte()) != 0)
         fileName += ch;
     return fileName;
 }
开发者ID:RareNCool,项目名称:MyToolkit,代码行数:8,代码来源:FileOpenHandler.cs


注:本文中的System.IO.Pipes.NamedPipeServerStream.ReadByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。