-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.pas
93 lines (77 loc) · 1.93 KB
/
MainForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
unit MainForm;
interface
uses
// Delphi-Cross-Socket
Net.CrossSocket.Base,
Net.CrossWebSocketClient,
Net.CrossWebSocketParser,
Utils.Utils,
//---------------------
System.SysUtils, System.Types, System.UITypes, System.Classes,
System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Layouts,
FMX.ListBox, FMX.Controls.Presentation, FMX.StdCtrls,
FMX.Edit;
type
THomeForm = class(TForm)
Button_Connect: TButton;
ListBox_Log: TListBox;
Edit_IP: TEdit;
Panel1: TPanel;
ClearEditButton1: TClearEditButton;
procedure RunWebSocketClient;
procedure Button_ConnectClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
HomeForm: THomeForm;
__WebSocket: ICrossWebSocket;
ip: String;
implementation
{$R *.fmx}
procedure THomeForm.RunWebSocketClient;
begin
__WebSocket := TCrossWebSocket.Create(ip);
__WebSocket.OnOpen(procedure
begin
ListBox_Log.Items.Add('WebSocket Opened');
end);
__WebSocket.OnClose(
procedure
begin
ListBox_Log.Items.Add('WebSocket Closed');
end);
__WebSocket.OnPing(
procedure
begin
ListBox_Log.Items.Add('WebSocket Ping');
end);
__WebSocket.OnPong(
procedure
begin
ListBox_Log.Items.Add('WebSocket Pong');
end);
__WebSocket.OnMessage(
procedure(const AMessageType: TWsMessageType; const AMessageData: TBytes)
var
LMessage: string;
begin
case AMessageType of
wtText:
LMessage := TUtils.GetString(AMessageData);
else
LMessage := TUtils.BytesToHex(AMessageData);
end;
ListBox_Log.Items.Add('Message: ' + LMessage);
end);
__WebSocket.Open;
end;
procedure THomeForm.Button_ConnectClick(Sender: TObject);
begin
ip := Edit_IP.Text;
RunWebSocketClient;
end;
end.