Esempio n. 1
0
 private void Server_PipeMessage(PipeMessage Reply)
 {
     if (callback != null)
     {
         callback.Invoke(Reply);
     }
 }
Esempio n. 2
0
 public void Send(string rServer, string pipename, byte[] SendBytes)
 {
     try
     {
         try
         {
             pipeStream = new NamedPipeClientStream(rServer, pipename, PipeDirection.InOut, PipeOptions.Asynchronous);
             pipeStream.Connect(1000);
             Debug.WriteLine("[Client] Pipe connection established");
         }
         catch (Exception ex)
         {
             Debug.WriteLine("[Client] Pipe connection failed");
             return;
         }
         PipeMessage message = new PipeMessage();
         message.SetPayload(typeof(byte[]), SendBytes);
         byte[] toSend = message.GetSerialized();
         pipeStream.BeginWrite(toSend, 0, toSend.Length, new AsyncCallback(AsyncSend), pipeStream);
     }
     catch (TimeoutException oEX)
     {
         Debug.WriteLine(oEX.Message);
     }
 }
Esempio n. 3
0
        private void WaitForConnectionCallBack(IAsyncResult iar)
        {
            try
            {
                pipeServer = (NamedPipeServerStream)iar.AsyncState;
                pipeServer.EndWaitForConnection(iar);

                byte[] buffer = new byte[6];
                pipeServer.Read(buffer, 0, 6);
                byte type = buffer[2];
                if (buffer[3] == (byte)(buffer[2] + ((buffer[0] ^ buffer[1]))))
                {
                    PipeMessage message = new PipeMessage();

                    int size = (buffer[0] << 8 | buffer[1]);
                    buffer = new byte[size];
                    pipeServer.Read(buffer, 0, size);
                    message.SetPayload(typeof(byte[]), buffer);

                    if (type == 1)
                    {
                        message.ConvertToString();
                    }
                    if (type == 2)
                    {
                        message.ConvertToBytes();
                    }
                    ReceivedCallback.Invoke(message);
                }

                pipeServer.Close();
                pipeServer = null;
                pipeServer = new NamedPipeServerStream(_pipeName, PipeDirection.InOut,
                                                       1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous);

                pipeServer.BeginWaitForConnection(
                    new AsyncCallback(WaitForConnectionCallBack), pipeServer);
            }
            catch
            {
                return;
            }
        }