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


C# NamedPipeClientStream.BeginRead方法代码示例

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


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

示例1: Start

        public void Start(string pipeName, string id)
        {
            _pipe = new NamedPipeClientStream(pipeName);
            _pipe.Connect();
            _pipe.BeginRead(_readBuffer, 0, _readBuffer.Length, OnRead, null);

            Write("hello", id);
        }
开发者ID:jakubmacek,项目名称:Griffin.Framework,代码行数:8,代码来源:CommunicationChannel.cs

示例2: NamedPipe

        public NamedPipe(string pipeName, int maxPipes = 10)
        {
            NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut);

            byte[] buf = new byte[1024];
            pipeClient.BeginRead(buf, 0, 1024, new AsyncCallback(test), null);

            // NamedPipeServerStream pipeServer = new NamedPipeServerStream(".", pipeName, PipeDirection.InOut, numThreads);
        }
开发者ID:pouc,项目名称:qv-extension-server,代码行数:9,代码来源:NamedPipe.cs

示例3: Start

	// Use this for initialization
	void Start () {
        pipeClient = new NamedPipeClientStream(
            ".", "testpipe", 
            PipeDirection.InOut);

        Debug.Log("Pipe Begin");
        pipeClient.Connect(10000);

        Debug.Log("Pipe Done: " + pipeClient.IsConnected);
    
        // 启动接收
        inBuffer = new byte[1024];
        pipeClient.BeginRead(inBuffer, 0, pipeClient.InBufferSize, onSvrDataReceived, pipeClient);
	}
开发者ID:Henry-T,项目名称:UnityPG,代码行数:15,代码来源:PipeClient.cs

示例4: ClientInstance

 /// <summary>
 /// Create an IPC client and attempt to connect to server.
 /// </summary>
 /// <param name="serverName">
 /// Name of server to connect to.
 /// </param>
 /// <param name="writeThrough">
 /// If true writes will bypass system cache and go straight to the pipe.
 /// </param>
 public ClientInstance(string serverName, bool writeThrough)
 {
     myBuffer = new byte[myBuffSize];
     myMemoryStream = new MemoryStream(myBuffSize);
     myMemoryStreamLock = new object();
     myThreadRunning = true;
     myThread = new Thread(new ThreadStart(ProcessClientStream));
     myThread.Start();
     myNamedPipeClientStream = new NamedPipeClientStream(
         ".",
         serverName,
         PipeDirection.InOut,
         writeThrough ? PipeOptions.Asynchronous | PipeOptions.WriteThrough : PipeOptions.Asynchronous);
     myNamedPipeClientStreamLock = new object();
     try { myNamedPipeClientStream.Connect(); }
     catch { return; }
     myNamedPipeClientStream.BeginRead(myBuffer, 0, myBuffer.Length, new AsyncCallback(OnClientReceive), null);
 }
开发者ID:InjectionDev,项目名称:UOMachine,代码行数:27,代码来源:ClientInstance.cs

示例5: QvxCommandWorker

        private void QvxCommandWorker()
        {
            try
            {
                if (pipeName == null) return;

                object state = new object();
                object connection = null;

                using (NamedPipeClientStream pipeClient = new NamedPipeClientStream(".", pipeName, PipeDirection.InOut))
                {
                    var buf = new byte[4];
                    var buf2 = new byte[4];
                    Int32 count = 0;
                    Int32 datalength = 0;
                    pipeClient.Connect(1000);
                    while (pipeClient.IsConnected)
                    {
                        try
                        {
                            #region Get QvxRequest
                            var iar = pipeClient.BeginRead(buf, 0, 4, null, state);
                            while (!iar.IsCompleted) Thread.Sleep(1);
                            count = pipeClient.EndRead(iar);
                            if (count != 4) throw new Exception("Invalid Count Length");
                            buf2[0] = buf[3];
                            buf2[1] = buf[2];
                            buf2[2] = buf[1];
                            buf2[3] = buf[0];
                            datalength = BitConverter.ToInt32(buf2, 0);
                            var data = new byte[datalength];
                            count = pipeClient.Read(data, 0, datalength);
                            if (count != datalength) throw new Exception("Invalid Data Length");

                            var sdata = ASCIIEncoding.ASCII.GetString(data);
                            sdata = sdata.Replace("\0", "");
                            QvxRequest request;
                            try
                            {
                                request = QvxRequest.Deserialize(sdata);

                            }
                            catch (Exception ex)
                            {
                                logger.Error(ex);
                                throw ex;
                            }
                            request.QVWindow = QVWindow;
                            request.Connection = connection;
                            #endregion

                            #region Handle QvxRequets
                            QvxReply result = null;
                            if (HandleQvxRequest != null)
                                result = HandleQvxRequest(request);

                            if (result == null)
                                result = new QvxReply() { Result = QvxResult.QVX_UNKNOWN_ERROR };
                            #endregion

                            #region Send QvxReply
                            sdata = "    " + result.Serialize() + "\0";
                            datalength = sdata.Length - 4;
                            buf2 = ASCIIEncoding.ASCII.GetBytes(sdata);
                            buf = BitConverter.GetBytes(datalength);
                            buf2[0] = buf[3];
                            buf2[1] = buf[2];
                            buf2[2] = buf[1];
                            buf2[3] = buf[0];
                            pipeClient.Write(buf2, 0, buf2.Length);
                            pipeClient.WaitForPipeDrain();
                            #endregion

                            #region Handle result States
                            if (result.Terminate)
                                close = true;
                            if (result.Connection != null)
                                connection = result.Connection;
                            if (result.SetConnectionNULL)
                                connection = null;
                            #endregion
                        }
                        catch (Exception ex)
                        {
                            logger.Error(ex);
                            Thread.Sleep(500);
                            close = true;
                        }

                        if (close)
                        {
                            close = false;
                            pipeClient.Close();
                        }

                        Thread.Sleep(5);
                    }
                }
                running = false;
            }
//.........这里部分代码省略.........
开发者ID:TonyWu,项目名称:QvxLib,代码行数:101,代码来源:QvxCommandClient.cs


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