示例#1
0
        MultiplexedConnection OnCreateConnection(int connectionId, object streamConnectionObject)
        {
            StreamConnection streamConnection = (StreamConnection)streamConnectionObject;

            if (streamConnection.ConnectionInfo.StartsWith("tcp:", StringComparison.OrdinalIgnoreCase))
            {
                int       port      = int.Parse(streamConnection.ConnectionInfo.Substring(4));
                TcpClient tcpClient = new TcpClient(AddressFamily.InterNetwork);
                tcpClient.LingerState.Enabled = true;
                tcpClient.NoDelay             = true;
                tcpClient.Connect(targetHost, port);

                return(new MultiplexedServiceTcpConnection(streamConnection, tcpClient, connectionId));
            }
            if (streamConnection.ConnectionInfo.StartsWith("np:", StringComparison.OrdinalIgnoreCase))
            {
                string pipe = streamConnection.ConnectionInfo.Substring(3);

                NamedPipeClientStream pipeClient = new NamedPipeClientStream(
                    ".",
                    pipe,
                    PipeDirection.InOut,
                    PipeOptions.Asynchronous,
                    TokenImpersonationLevel.Impersonation);
                pipeClient.Connect();
                return(new MultiplexedServiceNamedPipeConnection(streamConnection, pipeClient, connectionId));
            }
            throw new InvalidOperationException();
        }
示例#2
0
        public MultiplexedServiceTcpConnection(StreamConnection streamConnection, TcpClient tcpClient, int connectionId)
            : base(tcpClient.GetStream().Write, connectionId)
        {
            this.streamConnection = streamConnection;
            this.tcpClient        = tcpClient;

            outputPump = new MultiplexConnectionOutputPump(tcpClient.GetStream().Read, streamConnection.Stream.Write, connectionId);
            outputPump.BeginRunPump(PumpCompleted, null);
        }
        public MultiplexedServiceNamedPipeConnection(StreamConnection streamConnection, NamedPipeClientStream pipeClient, int connectionId)
            : base(pipeClient.Write, connectionId)
        {
            this.streamConnection = streamConnection;
            this.pipeClient       = pipeClient;

            outputPump = new MultiplexConnectionOutputPump(pipeClient.Read, streamConnection.Stream.Write, connectionId);
            outputPump.BeginRunPump(PumpCompleted, null);
        }
        MultiplexedConnection OnCreateConnection(int connectionId, object streamConnectionObject)
        {
            StreamConnection streamConnection = (StreamConnection)streamConnectionObject;

            if (streamConnection.ConnectionInfo.StartsWith("tcp:", StringComparison.OrdinalIgnoreCase))
            {
                int       port      = int.Parse(streamConnection.ConnectionInfo.Substring(4));
                TcpClient tcpClient = new TcpClient(AddressFamily.InterNetwork);
                tcpClient.LingerState.Enabled = true;
                tcpClient.NoDelay             = true;
                tcpClient.Connect(targetHost, port);

                return(new MultiplexedServiceTcpConnection(streamConnection, tcpClient, connectionId));
            }

            throw new InvalidOperationException();
        }