Ejemplo n.º 1
0
        public bool Connect()
        {
            try
            {
                lock (this)
                {
                    var pipe = new NamedPipeClientStream(Host, Name, PipeDirection.InOut, PipeOptions.Asynchronous);
                    pipe.Connect(1000);
                    pipe.ReadMode = PipeTransmissionMode.Message;
                    Pipe          = new PipeConnection(new byte[BufferSize], pipe);

                    pipe = new NamedPipeClientStream(Host, Name + PipeConnection.PUSH_SUFFIX, PipeDirection.InOut, PipeOptions.Asynchronous);
                    pipe.Connect(1000);
                    pipe.ReadMode = PipeTransmissionMode.Message;
                    PushPipe      = new PipeConnection(new byte[BufferSize], pipe);
                }
                BeginPushPipeRead();
                return(true);
            }
            catch
            {
                Dispose();
            }
            return(false);
        }
Ejemplo n.º 2
0
 protected void BeginPipeRead(PipeConnection conn)
 {
     if (!Running)
     {
         return;
     }
     conn.Pipe.BeginRead(conn.Buffer, 0, conn.Buffer.Length, OnPipeData, conn);
 }
Ejemplo n.º 3
0
        public void Dispose()
        {
            lock (this)
            {
                Pipe?.Dispose();
                Pipe = null;

                PushPipe?.Dispose();
                PushPipe = null;
            }
        }
Ejemplo n.º 4
0
        protected void OnPipeConnect(IAsyncResult ar)
        {
            try
            {
                lock (Pipes)
                {
                    if (ListeningPipe != null)
                    {
                        ListeningPipe.EndWaitForConnection(ar);
                        var conn = new PipeConnection(new byte[BufferSize], ListeningPipe);
                        ListeningPipe = null;

                        Pipes.Add(conn.Pipe, conn);

                        BeginPipeRead(conn);
                        Connected?.Invoke(conn);
                    }
                }
            }
            catch { }

            BeginPipeListen();
        }
Ejemplo n.º 5
0
        protected void OnPipeConnect(IAsyncResult ar)
        {
            var pipe = ar.AsyncState as NamedPipeServerStream;

            try
            {
                pipe.EndWaitForConnection(ar);
            }
            catch
            {
                Stop();
                return;
            }

            if (!Running)
            {
                pipe.Dispose();
                return;
            }
            lock (Pipes)
            {
                var conn = new PipeConnection(new byte[BufferSize], pipe);
                ListeningPipe = null;

                try
                {
                    BeginPipeRead(conn);
                    Pipes.Add(conn.Pipe, conn);
                }
                catch
                {
                    conn.Dispose();
                }
            }

            BeginPipeListen();
        }
Ejemplo n.º 6
0
 protected void BeginPipeRead(PipeConnection conn) => conn.Pipe.BeginRead(conn.Buffer, 0, conn.Buffer.Length, OnPipeData, conn);