Exemplo n.º 1
0
        private async Task TimeTcpAsync(StreamSocket tcpSocket)
        {
            // Step 1 is to write the reply.
            // TODO: CHANGE: fix this comment Step 2 is to read (and discard) all incoming data


            //NOTE: here's how to write data using a DataWriter
            //CHANGE: use datawriter
            var dw  = new DataWriter(tcpSocket.OutputStream);
            var now = TimeConversion.GetNow();

            dw.WriteUInt32(now);
            await dw.StoreAsync();

            Interlocked.Increment(ref Stats.NResponses);
            //await dw.FlushAsync(); // NOTE: this flush doesn't actually do anything useful.

            // CHANGE: REMOVE THE DIRECT STREAM WRITE
            await tcpSocket.OutputStream.FlushAsync();


            //CHANGE: no reading!

            Log(ServerOptions.Verbosity.Verbose, $"SERVER: TCP Stream closing down the current writing socket");

            if (Options.TcpPauseBeforeCloseTimeInMilliseconds >= 0)
            {
                await Task.Delay(Options.TcpPauseBeforeCloseTimeInMilliseconds);
            }
            tcpSocket.Dispose(); // The dispose is critical; without it the client won't ever finish reading our output
        }
Exemplo n.º 2
0
        private async Task TimeUdpAsync(DataReader dr, DataWriter dw, string remotePort)
        {
            var now = TimeConversion.GetNow();

            dw.WriteUInt32(now);
            await dw.StoreAsync();

            Interlocked.Increment(ref Stats.NResponses);
            Log(ServerOptions.Verbosity.Verbose, $"SERVER: UDP: reply with time {now} to remote port {remotePort}");

            dw.Dispose();
            Log(ServerOptions.Verbosity.Verbose, $"SERVER: UDP closing down the current writing socket for {now}");
        }