コード例 #1
0
ファイル: Program.cs プロジェクト: grendizeras/SocketSharp
        public static async Task Main(string[] args)
        {
            Console.WriteLine("Enter 'request' for request mode, else some other symbols");
            var mode = Console.ReadLine();

            if (mode == "request")
            {
                using (var request = new TCPRequest("127.0.0.1", 49999))
                {
                    while (true)
                    {
                        var message = Console.ReadLine();
                        SendRequest(request, message);//left without await intentionally
                        Console.WriteLine("Request sent; waiting for reply asynchronously");
                    }
                }
            }
            else
            {
                using (var con = new TCPConnection("127.0.0.1", 49999))
                {
                    con.OnConnected           += OnConnected;
                    con.OnReceive             += OnReceive;
                    con.OnConnectionException += OnConnectionException;
                    await con.ConnectAsync();

                    while (true)
                    {
                        var message = Console.ReadLine();
                        await con.SendAsync(Encoding.UTF8.GetBytes(message));
                    }
                }
            }
        }