Anonymous User
  Sunday, 22 March 2020
  3 Replies
  1.2K Visits
  Subscribe
I try to use TsgcWebSocketClient in TThread.Execute (Delphi Win32) with the following code:

WSClient := TsgcWebSocketClient.Create(nil);
WSClient.Host := IP;
WSClient.Port := Port;
WSClient.Options.Parameters := '';
WSClient.TLS := UseTLS;
WSClient.OnConnect := WSClientConnect;
WSClient.OnDisconnect := WSClientDisconnect;
WSClient.OnError := WSClientError;
WSClient.OnException := WSClientException;
WSClient.Specifications.RFC6455 := false; // chkOverWebSocket.Checked;
WSClient.Proxy.Enabled := false; // chkProxy.Checked;
WSClient.Proxy.Username := ''; // txtProxyUsername.Text;
WSClient.Proxy.Password := ''; // txtProxyPassword.Text;
WSClient.Proxy.Host := ''; // txtProxyHost.Text;
// if txtProxyPort.Text <> '' then
// WSClient.Proxy.Port := StrToInt(txtProxyPort.Text);
WSClient.Extensions.PerMessage_Deflate.Enabled := false; // chkCompressed.Checked;
WSClient.NotifyEvents := neNoSync;

MQTT := TsgcWSPClient_MQTT.Create(nil);
MQTT.Client := WSClient;
MQTT.Authentication.Enabled := True;
MQTT.Authentication.Username := User;
MQTT.Authentication.Password := Pass;
MQTT.MQTTVersion := mqtt311;
MQTT.OnMQTTPublish := MQTTPublish;

WSClient.Active := True;

repeat
dw := MsgWaitForTwoObjects(TerminateEvent, PublishEvent, false, 500, QS_ALLINPUT);
if dw = WAIT_OBJECT_0 then
break;
ProcessThreadMessages;
until false;

However after setting Active to True nothing happens. OnConnect OnDisconnect OnError OnException are never called.

Opening the same connection in the demo Client application works correctly however there everything is running in the VCL thread and components are on the form.

What am I doing wrong? I could not find any Delphi example that would be using TsgcWebSocketClient in TThread.Execute.