Beispiel #1
0
        public void NotConnected()
        {
            var client = new ByteClient(new SerialPort());

            Assert.IsFalse(client.Connected);
            Assert.AreEqual(client.Guid.ToString(), client.Name);
            Assert.AreEqual(new SerialPort().PortName, client.Address);
            Assert.DoesNotThrow(client.Close);
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            ByteClient cl = new ByteClient(sockname);

            while (true)
            {
                string msg = Console.ReadLine();
                msg = cl.Send_And_Recv(msg);
                Console.WriteLine(msg);
            }
        }
Beispiel #3
0
        public void Equality()
        {
            var        clientA  = new ByteClient(new SerialPort());
            ByteClient clientA2 = clientA;
            var        clientB  = new ByteClient(new SerialPort());

            Assert.IsTrue(clientA.Equals(clientA));
            Assert.IsFalse(clientA.Equals(clientB));
            Assert.IsTrue(clientA == clientA2);
            Assert.IsFalse(clientA == clientB);
            Assert.IsFalse(clientA != clientA2);
            Assert.IsTrue(clientA != clientB);
        }
Beispiel #4
0
        public static void InitByteServer()
        {
            var server = new ByteServer(GetIpAddress());

            server.Connected += (s, a) =>
            {
                Console.WriteLine("SERVER: Connected");
            };
            server.Disconnected += (s, a) =>
            {
                Console.WriteLine("SERVER: Disconnected");
            };
            server.DataReceived += (s, a) =>
            {
                Console.WriteLine(string.Concat("CLIENT: ", Encoding.UTF8.GetString(a.Data)));
            };

            var client = new ByteClient(GetIpAddress());

            client.Connected += (s, a) =>
            {
                Console.WriteLine("CLIENT: Connected");
            };
            client.Disconnected += (s, a) =>
            {
                Console.WriteLine("CLIENT: Disconnected");
            };
            client.DataReceived += (s, a) =>
            {
                Console.WriteLine(string.Concat("CLIENT: ", Encoding.UTF8.GetString(a.Data)));
            };

            while (true)
            {
                var val = Console.ReadLine();

                if (val == null || val.Length < 3)
                {
                    continue;
                }

                var key = val.Substring(0, 2);
                val = val.Substring(2);

                switch (key)
                {
                case "s:":
                {
                    switch (val)
                    {
                    case "start":
                        server.Start();
                        break;

                    case "stop":
                        server.Stop();
                        break;

                    default:
                        server.SendData(Encoding.UTF8.GetBytes(val));
                        break;
                    }
                }
                break;

                case "c:":
                    switch (val)
                    {
                    case "start":
                        client.Connect(autoReconnectOnError: true);
                        break;

                    case "stop":
                        client.Disconnect();
                        break;

                    default:
                        client.SendData(Encoding.UTF8.GetBytes(val));
                        break;
                    }
                    break;

                default:
                    break;
                }
            }
        }