Represents the session layer.
예제 #1
0
        public void CanReceiveByte()
        {
            byte expected = 0x03;

            Session session = new Session("localhost", DefaultPort);
            AcceptAndSendBytes(new byte[] { expected });

            byte actual = session.ReadByte();
            session.Close();

            Assert.AreEqual(expected, actual);
        }
예제 #2
0
        public void CanSendByte()
        {
            byte expected = 0xCA;
            Session session = new Session("localhost", DefaultPort);
            session.Write(expected);

            TcpClient client = server.AcceptTcpClient();
            int actual = client.GetStream().ReadByte();

            Assert.AreEqual(expected, actual);

            client.Close();
            session.Close();
        }
예제 #3
0
 public Presentation(string hostname, int port)
 {
     this.session = new Session(hostname, port);
     this.ResetCancellationToken();
 }
예제 #4
0
        public void CanSendBytes()
        {
            byte[] expected = new byte[] { 0xCA, 0xFE };
            Session session = new Session("localhost", DefaultPort);
            session.Write(expected);

            TcpClient client = server.AcceptTcpClient();
            byte[] actual = new byte[2];
            client.GetStream().Read(actual, 0, 2);

            Assert.AreEqual(expected, actual);

            client.Close();
            session.Close();
        }
예제 #5
0
 public void ThrowsExceptionTryingToWriteBytesOnClosed()
 {
     Session session = new Session("localhost", DefaultPort);
     server.AcceptTcpClient().Close();
     Assert.Throws<SocketException>(() => session.Write(new byte[] { 0xCA }));
 }
예제 #6
0
 public void ThrowsExceptionTryingToReadPacketOnClosed()
 {
     Session session = new Session("localhost", DefaultPort);
     server.AcceptTcpClient().Close();
     Assert.Throws<SocketException>(() => session.ReadPacket(0xCA));
 }
예제 #7
0
        public void ReceiveUntilByteNoRepeated()
        {
            Session session = new Session("localhost", DefaultPort);
            TcpClient client = server.AcceptTcpClient();

            byte sepByte = 0xCA;
            byte[] expected = new byte[] { 0xCA, 0xFE, 0xBE };
            client.GetStream().Write(expected, 0, expected.Length);

            byte[] actual = session.ReadPacket(sepByte);
            Assert.AreEqual(expected, actual);

            client.Close();
            session.Close();
        }