Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            ByteServer cl = new ByteServer(sockname);

            cl.Dummy_Serve();
        }
Ejemplo n.º 2
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;
                }
            }
        }