mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-19 13:09:17 +02:00
Added SSL support for Websocket client.
This commit is contained in:
parent
9c72ab651d
commit
a5486e04cd
@ -19,7 +19,7 @@ unit fpwebsocketclient;
|
|||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
sysutils, classes, fpwebsocket, ssockets;
|
sysutils, classes, fpwebsocket, ssockets, sslsockets, opensslsockets, fpopenssl;
|
||||||
|
|
||||||
Type
|
Type
|
||||||
EWebSocketClient = Class(EWebSocket);
|
EWebSocketClient = Class(EWebSocket);
|
||||||
@ -276,17 +276,27 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TCustomWebsocketClient.Connect;
|
procedure TCustomWebsocketClient.Connect;
|
||||||
|
var
|
||||||
|
SSLHandler: TSSLSocketHandler;
|
||||||
begin
|
begin
|
||||||
If Active then
|
If Active then
|
||||||
Exit;
|
Exit;
|
||||||
// Safety: Free any dangling objects before recreating
|
// Safety: Free any dangling objects before recreating
|
||||||
FreeConnectionObjects;
|
FreeConnectionObjects;
|
||||||
FSocket:=TInetSocket.Create(HostName,Port,ConnectTimeout);
|
SSLHandler := nil;
|
||||||
|
if UseSSL then
|
||||||
|
begin
|
||||||
|
SSLHandler := TOpenSSLSocketHandler.GetDefaultHandler;
|
||||||
|
SSLHandler.VerifyPeerCert := False;
|
||||||
|
end;
|
||||||
|
FSocket:=TInetSocket.Create(HostName,Port,ConnectTimeout, SSLHandler);
|
||||||
FTransport:=TWSClientTransport.Create(FSocket);
|
FTransport:=TWSClientTransport.Create(FSocket);
|
||||||
FConnection:=CreateClientConnection(FTransport);
|
FConnection:=CreateClientConnection(FTransport);
|
||||||
FConnection.OnMessageReceived:=@MessageReceived;
|
FConnection.OnMessageReceived:=@MessageReceived;
|
||||||
FConnection.OnControl:=@ControlReceived;
|
FConnection.OnControl:=@ControlReceived;
|
||||||
FCOnnection.OutgoingFrameMask:=Self.OutGoingFrameMask;
|
FCOnnection.OutgoingFrameMask:=Self.OutGoingFrameMask;
|
||||||
|
if UseSSL then
|
||||||
|
FSocket.Connect;
|
||||||
FActive:=True;
|
FActive:=True;
|
||||||
if not DoHandShake then
|
if not DoHandShake then
|
||||||
Disconnect(False)
|
Disconnect(False)
|
||||||
|
Loading…
Reference in New Issue
Block a user