Hi, @John_Brochue thanks for your answer.
It’s not clear to me why opening a socket to some sites work and for some sites doesn’t work
For example this works:
wifi.SetTlsServerRootCertificate(caGoogle);
TestSocket("www.google.de", "/", 443, SPWF04SxConnectionType.Tcp, SPWF04SxConnectionSecurityType.Tls);
This works not:
wifi.SetTlsServerRootCertificate(Resources.GetBytes(Resources.BinaryResources.Digicert___GHI));
wifi.ForceSocketsTls = true;
wifi.ForceSocketsTlsCommonName = "*.ghielectronics.com";
TestSocket("www.ghielectronics.com", "/robots.txt", 443, SPWF04SxConnectionType.Tcp, SPWF04SxConnectionSecurityType.Tls, "*.ghielectronics.com");
The code of ‘TestSocket’ is:
private static void TestSocket(string host, string url, int port, SPWF04SxConnectionType connectionType, SPWF04SxConnectionSecurityType connectionSecurity, string commonName = null)
{
var buffer = new byte[512];
int id = 0;
try
{
id = wifi.OpenSocket(host, port, connectionType, connectionSecurity, commonName);
}
catch (Exception ex)
{
var result = ex.Message;
}
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();
cont = false;
}
wifi.CloseSocket(id);
}
I have added the driver to my code.
When opening the socket works for example I get:
First: a = ,b = Loading:1:2
Second: a = On:216.58.212.227:0,b =
When opening the socket doesn’t work, both variables a and b stay empty.
The line:
this.FinishCommand(cmd);
is never reached and I get a Type 0x03 message with indication code 0x4A which seems to mean ‘failed to open socket’