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


C# NamedPipeClientStream.ReadByte方法代码示例

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


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

示例1: readMessage

 private byte[] readMessage(NamedPipeClientStream client)
 {
     byte[] message = new byte[0];
     _offset = 0;
     _current = new List<byte>();
     while (true)
     {
         var i = client.ReadByte();
         if (i == -1)
         {
             _offset = 0;
             return new byte[0];
         }
         if (i == 0)
         {
             var buffer = new byte[_offset];
             Array.Copy(_bytes, buffer, _offset);
             _current.AddRange(buffer);
             message = _current.ToArray();
             _current = new List<byte>();
             _offset = 0;
             break;
         }
         _bytes[_offset] = Convert.ToByte(i);
         _offset++;
         if (_offset == _bytes.Length)
         {
             _current.AddRange(_bytes);
             _offset = 0;
         }
     }
     return message;
 }
开发者ID:jonwingfield,项目名称:AutoTest.Net,代码行数:33,代码来源:PipeClient.cs

示例2: Read_bytes_from_server

        public void Read_bytes_from_server()
        {
            new Thread(Server).Start();

             using (var s = new NamedPipeClientStream("pipedream"))
             {
                 s.Connect();
                 var read = 0;
                 while (read <100)
                 {
                     read = s.ReadByte();
                     Console.WriteLine(read + " ");
                 }
             }
        }
开发者ID:simonlaroche,项目名称:DumpingGrounds,代码行数:15,代码来源:PipeStreams.cs

示例3: PingPong_OtherProcess

        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;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:18,代码来源:NamedPipesTests.cs

示例4: PingPong

        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);
                }
            }
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:24,代码来源:NamedPipesTests.cs

示例5: ReadNextCommandMessage

        private static String ReadNextCommandMessage(NamedPipeClientStream pipe)
        {
            String xml = null;
               int data_len = 0;

               _logger.LogMsg(Level.Debug, "ReadNextCommandMessage(): Attempting to retrieve message from command pipe. ");

            try
            {
                // TO DO: make this more efficient. We also need to handle larger messages / dynamic buffer size.
                byte[] mybuf = new byte[2048];
                byte[] len_buf = new byte[4];
                for( int ii = 0; ii < mybuf.Length; ii++ )
                {
                    mybuf[ii] = 0xFF;
                }

                _logger.LogMsg(Level.Debug, "Checking for pipe stream status.");
                if (pipe.IsConnected)
                {

                    _logger.LogMsg(Level.Debug, "Pipe is connected. Attempting binary read.");

                    int itmp = 0;
                    int pos = 0;
                    while (itmp >= 0)
                    {
                        itmp = pipe.ReadByte();
                        if (itmp == -1)
                        {
                            _logger.LogMsg(Level.Debug, "End of read stream, -1 returned.");
                            break;
                        }
                        mybuf[pos] = (Byte)itmp;
                        if (pos > 3)
                        {
                            if (mybuf[pos] == 0x00)
                            {
                                break;
                            }
                            else
                            {
                                xml += (char)mybuf[pos];
                            }

                        }
                        else
                        {
                            len_buf[3 - pos] = (byte)itmp;
                        }

                        pos++;
                    }
                    data_len = BitConverter.ToInt32(len_buf, 0);
                    _logger.LogMsg(Level.Debug, String.Format("Bytes read (+1) = {0}, QlkView data length = {1}.", (pos + 1).ToString(), data_len.ToString()));

                }
                else
                {
                    _logger.LogMsg(Level.Warn, "Pipe is not connected.");
                }

            }
            catch (System.Exception ex)
            {
                Debug.WriteLine("Error in ReadNextCommandMessage(): " + ex.Message);
                throw ex;
            }

            return xml;
        }
开发者ID:jagdishRangaswamy,项目名称:cloudera-connector,代码行数:71,代码来源:Program.cs

示例6: PipeThread

            private void PipeThread(object id)
            {
                try
                {
                    using (var pipe = new NamedPipeClientStream(".", (string)id + "\\root", PipeDirection.In))
                    {
                        pipe.Connect();

                        BinaryReader rd = new BinaryReader(pipe);

                        for (;;)
                        {
                            lock (mSync)
                                if (mShutdown)
                                    return;

                            int op = pipe.ReadByte();
                            if (op < 0)
                                return;

                            ProcessPipeThreadEvent(rd, op);
                        }
                    }
                }
                catch (Exception ex)
                {
                    lock (mSync)
                        mError.Add(ex);
                }
            }
开发者ID:guocqforc,项目名称:managed-lzma,代码行数:30,代码来源:Trace.cs

示例7: ReadToEnd

 private static string ReadToEnd(NamedPipeClientStream pipe)
 {
     List<char> input = new List<char>();
     char c = (char)pipe.ReadByte();
     while (c != ProcessingKeys.EndMessage)
     {
         input.Add(c);
         c = (char)pipe.ReadByte();
     }
     if (input.Count > 0)
         return new string(input.ToArray());
     return null;
 }
开发者ID:coapp-test,项目名称:VM_SelfManager,代码行数:13,代码来源:VM_SelfManager.cs

示例8: ReadBytesToEnd

 private static byte[] ReadBytesToEnd(NamedPipeClientStream pipe)
 {
     List<byte> input = new List<byte>();
     byte c = (byte)pipe.ReadByte();
     while (c != ProcessingKeys.EndMessage)
     {
         input.Add(c);
         c = (byte)pipe.ReadByte();
     }
     if (input.Count > 0)
         return input.ToArray();
     return null;
 }
开发者ID:coapp-test,项目名称:VM_SelfManager,代码行数:13,代码来源:VM_SelfManager.cs

示例9: ProcessDeleteSnapshot

            protected void ProcessDeleteSnapshot(NamedPipeClientStream pipe, CancellationToken token)
            {
                // Are we deleting a whole tree?
                char c = (char)pipe.ReadByte();
                if (c == ProcessingKeys.DeleteSnapshot)
                {
                    ProcessDeleteTree(pipe, token);
                    return;
                }
                //Get name for snapshot (if any)
                string name = (c != ProcessingKeys.EndMessage ? String.Concat(c, ReadToEnd(pipe)) : null);
                ManagementObject VSMS = Utility.GetServiceObject("MSVM_VirtualSystemManagementService");
                //ManagementClass VSMS = new ManagementClass(new ManagementScope(@"root\virtualization", null).Path.Path, "MSVM_VirtualSystemManagementService", null);
                ManagementObject Snapshot = Utility.GetSnapshot(VMName, name);
                if (Snapshot == null)
                    return;
                ManagementBaseObject input = VSMS.GetMethodParameters("RemoveVirtualSystemSnapshot");
                input["SnapshotSettingData"] = Snapshot.Path.Path;

                if (Utility.WaitForJob(VSMS.InvokeMethod("RemoveVirtualSystemSnapshot", input, null)))
                    write("Deleted snapshot:  " + VMName + "::" + (name ?? "current"));
                else
                    write("Failed to delete snapshot:  " + VMName + "::" + (name ?? "current"), EventLogEntryType.Error);
            }
开发者ID:coapp-test,项目名称:VM_SelfManager,代码行数:24,代码来源:VM_SelfManager.cs

示例10: Listen

            protected void Listen(NamedPipeClientStream pipe, CancellationToken token)
            {
                byte current = (byte) pipe.ReadByte();
                while (current != 255 && !token.IsCancellationRequested)
                {
                    //ProcessMessage(current, pipe, token);
                    if (token.IsCancellationRequested)
                        return;

                    switch (current)
                    {
                        case ProcessingKeys.BootVM:
                            ProcessBootVM(pipe, token);
                            break;
                        case ProcessingKeys.NewSnapshot:
                            ProcessNewSnapshot(pipe, token);
                            break;
                        case ProcessingKeys.OpenSnapshot:
                            ProcessOpenSnapshot(pipe, token);
                            break;
                        case ProcessingKeys.DeleteSnapshot:
                            ProcessDeleteSnapshot(pipe, token);
                            break;
                        case ProcessingKeys.WriteToLog:
                            ProcessWriteToLog(pipe, token);
                            break;
                        case ProcessingKeys.ReadFromLog:
                            ProcessReadFromLog(pipe, token);
                            break;
                    }

                    current = (byte) pipe.ReadByte();
                }
                if (current == 255)
                    this.Dispose();
            }
开发者ID:coapp-test,项目名称:VM_SelfManager,代码行数:36,代码来源:VM_SelfManager.cs

示例11: GetResponse

        private Response GetResponse(Request request)
        {
            _pipeClient = CreateClientPipe();
            TryConnect(_pipeClient);

            _pipeClient.WriteByte((byte)request);
            _pipeClient.WriteByte((byte)_pos);
            _pipeClient.WaitForPipeDrain();

            Response response = (Response)_pipeClient.ReadByte();
            return response;
        }
开发者ID:RoadToExclusivity,项目名称:PP,代码行数:12,代码来源:PhilosopherClient.cs


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