Example #1
0
        public PipeClient(string serverName, string message)
        {
            m_pipe = new NamedPipeClientStream(serverName, "Echo",
                PipeDirection.InOut,
                PipeOptions.Asynchronous | PipeOptions.WriteThrough);
            m_pipe.Connect();//必须先连接才能设置ReadMode
            m_pipe.ReadMode = PipeTransmissionMode.Message;

            //异步地将数据发送给服务器
            Byte[] output = Encoding.UTF8.GetBytes(message);

            m_pipe.BeginWrite(output, 0, output.Length, WriteDone, null);
        }
Example #2
0
 public void Send(string SendStr, string PipeName, int TimeOut = 100000)
 {
     try
     {
         NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous);
         pipeStream.Connect(TimeOut);
         // Debug.WriteLine("[Client] Pipe connection established");
         byte[] _buffer = Encoding.UTF8.GetBytes(SendStr);
         pipeStream.BeginWrite(_buffer, 0, _buffer.Length, AsyncSend, pipeStream);
     }
     catch (TimeoutException oEX)
     {
         // Debug.WriteLine(oEX.Message);
     }
 }
Example #3
0
        public void Send(string SendStr, string PipeName, int TimeOut = 1000)
        {
            try
            {
                NamedPipeClientStream pipeStream = new NamedPipeClientStream(".", PipeName, PipeDirection.Out, PipeOptions.Asynchronous);

                // The connect function will indefinitely wait for the pipe to become available
                // If that is not acceptable specify a maximum waiting time (in ms)
                pipeStream.Connect(TimeOut);
                Debug.WriteLine("[Client] Pipe connection established");

                byte[] _buffer = Encoding.UTF8.GetBytes(SendStr);
                pipeStream.BeginWrite(_buffer, 0, _buffer.Length, AsyncSend, pipeStream);
            }
            catch (TimeoutException oEX)
            {
                Debug.WriteLine(oEX.Message);
            }
        }