Пример #1
0
        public ChannelWrapperTests(TaskClientConnector connector)
            : base(connector)
        {
            // init various things
            receiver = new SocketAsyncEventArgs();
            receiver.SetBuffer(receiveBuffer, 0, receiveBuffer.Length);
            receiverArgs = new DirectBytesReceivedEventArgs(receiver);

            sender = new SocketAsyncEventArgs();
            sender.SetBuffer(sendBuffer, 0, sendBuffer.Length);
            sendBufferWriter = new MemoryStream(sendBuffer, true);

            // establish a connection
            Task<Socket> task = connector.ConnectAsync();
            task.Wait(TimeSpan.FromSeconds(2));

            wrapper = new ChannelWrapperBase(task.Result, receiver, receiverArgs, sender, sendBufferWriter);

            WaitForServerConnections(1);

            // get the other end of the socket
            otherEnd = Connections[0];

            // set up event handlers
            wrapper.BytesReceived += OnBytesReceived;
            wrapper.Closed += OnClosed;
            wrapper.DuplexChannelClosed += OnDuplexChannelClosed;

            // start receive loop
            wrapper.Start();
        }
Пример #2
0
        public ImmutableChannel(Socket channelSocket, SocketAsyncEventArgs receiver, SocketAsyncEventArgs sender, DirectBytesReceivedEventArgs receiverArgs, MemoryStream senderWriter, object additionalData = null)
        {
            this.channelSocket = channelSocket;

            wrapper = new ChannelWrapperBase(channelSocket, receiver, receiverArgs, sender, senderWriter);
            wrapper.BytesReceived       += OnBytesReceived;
            wrapper.Closed              += OnChannelClosed;
            wrapper.DuplexChannelClosed += OnChannelError;

            this.additionalData = additionalData;
        }