Exemplo n.º 1
0
        /// <summary>
        /// Demonstrates the simplest calling pattern.
        /// </summary>
        /// <param name="patternType">Normally only set when testing that the code works (setting the pattern to the 'Fixed' pattern)</param>
        /// <returns></returns>
        public static async Task <CharGenClient_Rfc_864.CharGenResult> RunTcpAsync(CharGenServer_Rfc_864.ServerOptions.PatternType patternType = CharGenServer_Rfc_864.ServerOptions.PatternType.Classic72)
        {
            // Hint: the using here means that the server is automatically closed
            // after the code is done. If you don't do that, the server stays open.
            using (var server = new CharGenServer_Rfc_864())
            {
                server.Options.OutputPattern = patternType;
                await server.StartAsync();

                var client = new CharGenClient_Rfc_864();
                // You only get the CharGen'd result from TCP with the final CloseAsync()
                // But for UDP  you get the returned packet.
                var partialResult = await client.WriteAsync(
                    new Windows.Networking.HostName("localhost"),
                    server.Options.Service,
                    CharGenClient_Rfc_864.ProtocolType.Tcp);

                // TODO: remove magic value?
                // Wait for the CharGen to have worked. The server is right here, so the
                // CharGen should be almost instantaneous.
                await Task.Delay(100);

                var completeResult = await client.CloseAsync(); // Close is essential for TCP.

                return(completeResult);
            }
        }
 private async void OnClose(object sender, RoutedEventArgs e)
 {
     if (client != null)
     {
         await client.CloseAsync();
     }
     client = null;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Demonstrates the simplest calling pattern
        /// </summary>
        /// <param name="patternType">Normally only set when testing that the code works (setting the pattern to the 'Fixed' pattern)</param>
        /// <returns></returns>
        public static async Task <CharGenClient_Rfc_864.CharGenResult> RunUdpAsync(CharGenServer_Rfc_864.ServerOptions.PatternType patternType = CharGenServer_Rfc_864.ServerOptions.PatternType.Classic72)
        {
            // Hint: the using here means that the server is automatically closed
            // after the code is done. If you don't do that, the server stays open.
            using (var server = new CharGenServer_Rfc_864())
            {
                server.Options.OutputPattern = patternType;
                await server.StartAsync();

                var client = new CharGenClient_Rfc_864();
                var result = await client.WriteAsync(
                    new Windows.Networking.HostName("localhost"),
                    server.Options.Service,
                    CharGenClient_Rfc_864.ProtocolType.Udp);

                await client.CloseAsync(); // Close is really needed for TCP.

                return(result);
            }
        }
Exemplo n.º 4
0
        public async Task Test_CharGen_Good_Path_Tcp()
        {
            using (var server = new CharGenServer_Rfc_864())
            {
                server.Options.OutputPattern = CharGenServer_Rfc_864.ServerOptions.PatternType.Fixed;
                var client = new CharGenClient_Rfc_864();
                await server.StartAsync();

                var result1 = await client.WriteAsync(new HostName("localhost"), server.Options.Service, CharGenClient_Rfc_864.ProtocolType.Tcp);

                Infrastructure.IfTrueError(result1.Succeeded != CharGenClient_Rfc_864.CharGenResult.State.InProgress, "TCP status should be in progress");

                await Task.Delay(100); //TODO: artificial delay to get the results.

                var expected = CharGenServer_Rfc_864.GetSampleReturn();
                var result3  = await client.CloseAsync();

                Infrastructure.IfTrueError(result3.Succeeded != CharGenClient_Rfc_864.CharGenResult.State.Succeeded, "Close TCP status should be succeeded");
                Infrastructure.IfTrueError(result3.Value != expected, $"Should have gotten back {expected}, not {result3.Value}");
            }
        }