public MultiplexedTcpConnection(TcpClient tcpClient, QueueBufferedStream multiplexedOutputStream)
     : base(tcpClient.GetStream().Write)
 {
     this.tcpClient = tcpClient;
     this.outputPump = new MultiplexConnectionOutputPump(tcpClient.GetStream().Read, multiplexedOutputStream.Write, Id);
     this.outputPump.BeginRunPump(PumpComplete, null);
 }
예제 #2
0
 public MultiplexedTcpConnection(TcpClient tcpClient, QueueBufferedStream multiplexedOutputStream)
     : base(tcpClient.GetStream().Write)
 {
     this.tcpClient  = tcpClient;
     this.outputPump = new MultiplexConnectionOutputPump(tcpClient.GetStream().Read, multiplexedOutputStream.Write, Id);
     this.outputPump.BeginRunPump(PumpComplete, null);
 }
예제 #3
0
        private DuplexChannelFactory <IDataExchangeChannel> CreateDataChannelFactory(QueueBufferedStream multiplexedInputStream)
        {
            ReplyChannelStreamConnector connector = new ReplyChannelStreamConnector(multiplexedInputStream);
            DuplexChannelFactory <IDataExchangeChannel> dataChannelFactory = new DuplexChannelFactory <IDataExchangeChannel>(connector, streamBinding);

            dataChannelFactory.Endpoint.Behaviors.Add(relayCreds);
            return(dataChannelFactory);
        }
예제 #4
0
        void EnsureConnection()
        {
            lock (connectLock)
            {
                if (this.dataChannel == null || this.dataChannel.State != CommunicationState.Opened)
                {
                    this.multiplexedOutputStream = new ThrottledQueueBufferedStream(5);

                    QueueBufferedStream multiplexedInputStream = new QueueBufferedStream();
                    this.dataChannelFactory = CreateDataChannelFactory(multiplexedInputStream);
                    this.dataChannelFactory.Open();

                    this.dataChannel = dataChannelFactory.CreateChannel(new EndpointAddress("sb:"), endpointVia);

                    try
                    {
                        this.dataChannel.Open();
                        this.dataChannel.Closed  += DataChannelClosed;
                        this.dataChannel.Faulted += DataChannelClosed;

                        IHybridConnectionStatus status = dataChannel.GetProperty <IHybridConnectionStatus>();
                        if (status != null)
                        {
                            status.ConnectionStateChanged += (o, e) =>
                            {
                                Trace.TraceInformation("Data channel upgraded to direct connection.");
                            };
                        }

                        this.dataChannel.Connect("tcp:" + toPort.ToString());

                        this.inputPump = new MultiplexConnectionInputPump(multiplexedInputStream.Read, CorrelateConnection, null);
                        this.inputPump.Run(false);

                        this.outputPump = new StreamBufferWritePump(multiplexedOutputStream, WriteToDataChannel);
                        this.dataChannel.Extensions.Add(new DataExchangeChannelFaultHelper(outputPump));
                        this.outputPump.BeginRunPump(MultiplexPumpCompleted, null);

                        return;
                    }
                    catch (AuthorizationFailedException af)
                    {
                        Trace.TraceError("Authorization failed: {0}", af.Message);
                        if (dataChannel != null)
                        {
                            dataChannel.Abort();
                            dataChannel = null;
                        }
                        throw;
                    }
                    catch (Exception ex)
                    {
                        this.dataChannelFactory.Abort();
                        this.dataChannelFactory = null;

                        Trace.TraceError("Unable to establish data channel: {0}", ex.Message);
                        if (dataChannel != null)
                        {
                            dataChannel.Abort();
                            dataChannel = null;
                        }
                        throw;
                    }
                }
            }
        }
        void EnsureConnection()
        {
            lock (connectLock)
            {
                if (this.dataChannel == null || this.dataChannel.State != CommunicationState.Opened)
                {
                    this.multiplexedOutputStream = new ThrottledQueueBufferedStream(5);

                    QueueBufferedStream multiplexedInputStream = new QueueBufferedStream();
                    this.dataChannelFactory = CreateDataChannelFactory(multiplexedInputStream);
                    this.dataChannelFactory.Open();

                    this.dataChannel = dataChannelFactory.CreateChannel(new EndpointAddress("sb:"), endpointVia);

                    try
                    {
                        this.dataChannel.Open();
                        this.dataChannel.Closed += DataChannelClosed;
                        this.dataChannel.Faulted += DataChannelClosed;

                        IHybridConnectionStatus status = dataChannel.GetProperty<IHybridConnectionStatus>();
                        if (status != null)
                        {
                            status.ConnectionStateChanged += (o, e) =>
                            {
                                Trace.TraceInformation("Data channel upgraded to direct connection.");
                            };
                        }

                        this.dataChannel.Connect("tcp:" + toPort.ToString());

                        this.inputPump = new MultiplexConnectionInputPump(multiplexedInputStream.Read, CorrelateConnection, null);
                        this.inputPump.Run(false);

                        this.outputPump = new StreamBufferWritePump(multiplexedOutputStream, WriteToDataChannel);
                        this.dataChannel.Extensions.Add(new DataExchangeChannelFaultHelper(outputPump));
                        this.outputPump.BeginRunPump(MultiplexPumpCompleted, null);

                        return;
                    }
                    catch (AuthorizationFailedException af)
                    {
                        Trace.TraceError("Authorization failed: {0}", af.Message);
                        if (dataChannel != null)
                        {
                            dataChannel.Abort();
                            dataChannel = null;
                        }
                        throw;
                    }
                    catch (Exception ex)
                    {
                        this.dataChannelFactory.Abort();
                        this.dataChannelFactory = null;

                        Trace.TraceError("Unable to establish data channel: {0}", ex.Message);
                        if (dataChannel != null)
                        {
                            dataChannel.Abort();
                            dataChannel = null;
                        }
                        throw;
                    }
                }
            }
        }
 private DuplexChannelFactory<IDataExchangeChannel> CreateDataChannelFactory(QueueBufferedStream multiplexedInputStream)
 {
     ReplyChannelStreamConnector connector = new ReplyChannelStreamConnector(multiplexedInputStream);
     DuplexChannelFactory<IDataExchangeChannel> dataChannelFactory = new DuplexChannelFactory<IDataExchangeChannel>(connector, streamBinding);
     dataChannelFactory.Endpoint.Behaviors.Add(relayCreds);
     return dataChannelFactory;
 }