Exemplo n.º 1
0
        private static void TestSocket(string host, string url, int port, SPWF04SxConnectionType connectionType, SPWF04SxConnectionSecurityType connectionSecurity, string commonName = null)
        {
            var buffer = new byte[512];
            var id     = wifi.OpenSocket(host, port, connectionType, connectionSecurity, commonName);

            var cont = true;

            while (cont)
            {
                var start = DateTime.UtcNow;

                wifi.WriteSocket(id, Encoding.UTF8.GetBytes($"GET {url} HTTP/1.1\r\nHost: {host}\r\n\r\n"));

                Thread.Sleep(100);

                var total = 0;
                var first = true;
                while ((wifi.QuerySocket(id) is var avail && avail > 0) || first || total < 120)
                {
                    if (avail > 0)
                    {
                        first = false;

                        var read = wifi.ReadSocket(id, buffer, 0, Math.Min(avail, buffer.Length));

                        total += read;

                        Debugger.Log(0, "", Encoding.UTF8.GetString(buffer, 0, read));
                    }

                    Thread.Sleep(100);
                }

                Debug.WriteLine($"\r\nRead: {total:N0} in {(DateTime.UtcNow - start).TotalMilliseconds:N0}ms");

                WaitForButton();
            }

            wifi.CloseSocket(id);
        }