示例#1
0
        private static void Main(string[] args)
        {
#if TCP
            using TcpClientEap client = new TcpClientEap(512);
#else
            using UdpClientEap client = new UdpClientEap(512);
#endif
            client.Disconnected += (c, r) => { Console.WriteLine(r + " | Disconnected"); };

            client.AddCommand(1, DeserializePacketToString);

            client.AddDataReceivedCallback(
                1, (client1, data, responseID) =>
            {
                string request = (string)data;

                SendRequestAndWaitForResponse(client1, request, responseID);

                return(true);
            });

            Thread.Sleep(100);
            Console.WriteLine(
                client.Connect("127.0.0.1", 3000, b => b.ReceiveBufferSize = 64 * 1024)
                    ? "CONNECTED"
                    : "CONNECT FAILED");

            Console.WriteLine("press any key to exit...");
            Console.ReadKey();
        }
示例#2
0
        private static async Task Main(string[] args)
        {
#if TCP
            using TcpClientEap client = new TcpClientEap(512);
#else
            using UdpClientEap client = new UdpClientEap(512);
#endif
            client.Disconnected += (c, r) => { Console.WriteLine(r + " | Disconnected"); };
            client.AddCommand(
                (in Packet packet) =>
            {
                Console.WriteLine(
                    "{0} >= {1}  ==  {2}", packet.Buffer.Length, packet.Length,
                    packet.Buffer.Length >= packet.Length);
                return(true);
            }, 1);