コード例 #1
0
ファイル: Client.cs プロジェクト: gamover321/AsyncServer
        public async Task <DateTimeOffset> GetDate()
        {
            using var client = new TcpClient();
            client.Connect(Ip, Port);
            var connection = new ClientConnection(client);

            await WriteHeader(connection);
            await WriteCommandCode(connection, CommandCodeEn.GetDate);
            await WriteGuid(connection);
            await WriteDataLength(connection, 0);

            var caption = await connection.ReadStringAsync(CancellationToken);

            var unixDate = await connection.ReadInt64Async(CancellationToken);

            var date = DateTimeOffset.FromUnixTimeSeconds(unixDate);

            Console.WriteLine($"<- {caption}{date}");

            return(date);
        }