コード例 #1
0
ファイル: TcpTransport.cs プロジェクト: mehdidk/TLSharp
        public async Task <TcpMessage> Receieve()
        {
            var buffer         = new byte[_tcpClient.ReceiveBufferSize];
            var availableBytes = await _tcpClient.GetStream().ReadAsync(buffer, 0, buffer.Length);

            var result = buffer.Take(availableBytes).ToArray();

            return(TcpMessage.Decode(result));
        }
コード例 #2
0
ファイル: TcpTransport.cs プロジェクト: sochix/TLSharp
        public async Task Send(byte[] packet)
        {
            if (!_tcpClient.Connected)
                throw new InvalidOperationException("Client not connected to server.");

            var tcpMessage = new TcpMessage(sendCounter, packet);

            await _tcpClient.GetStream().WriteAsync(tcpMessage.Encode(), 0, tcpMessage.Encode().Length);
            sendCounter++;
        }
コード例 #3
0
ファイル: TcpTransport.cs プロジェクト: Marjani/TLSharp
        public async Task Send(byte[] packet)
        {
            if (!_tcpClient.Connected)
            {
                throw new InvalidOperationException("Client not connected to server.");
            }

            var tcpMessage = new TcpMessage(sendCounter, packet);

            await _tcpClient.GetStream().WriteAsync(tcpMessage.Encode(), 0, tcpMessage.Encode().Length);

            sendCounter++;
        }
コード例 #4
0
ファイル: TcpTransport.cs プロジェクト: CheshireCaat/TLSharp
        public async Task Send(byte[] packet, CancellationToken token = default(CancellationToken))
        {
            if (!_tcpClient.Connected)
            {
                throw new InvalidOperationException("Client not connected to server.");
            }

            var tcpMessage = new TcpMessage(sendCounter, packet);

            await _stream.WriteAsync(tcpMessage.Encode(), 0, tcpMessage.Encode().Length, token).ConfigureAwait(false);

            sendCounter++;
        }
コード例 #5
0
        public async Task <byte[]> Receive(CancellationToken token = default(CancellationToken))
        {
            token.ThrowIfCancellationRequested();

            TcpMessage result = await this.transport.Receive(token).ConfigureAwait(false);

            using (MemoryStream memoryStream = new MemoryStream(result.Body))
            {
                using (BinaryReader binaryReader = new BinaryReader(memoryStream))
                {
                    long authKeyid     = binaryReader.ReadInt64();
                    long messageId     = binaryReader.ReadInt64();
                    int  messageLength = binaryReader.ReadInt32();

                    byte[] response = binaryReader.ReadBytes(messageLength);

                    return(response);
                }
            }
        }