Skip to content

Commit 1962762

Browse files
ADD: Socket example
1 parent 1ece325 commit 1962762

File tree

7 files changed

+749
-0
lines changed

7 files changed

+749
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ Collection of classes and examples that are mainly related to Serial and Network
3636
| MQTT_Publisher | Demo that can send MQTT Publish messages to a given IP-Address (no security login) |
3737
| Modbus_Client | Application to emulate a MODBUS-Slave device |
3838
| Modbus_Diagnostic | Shows a implementation for the MODBUS RTU, MODBUS-TCP and MODBUS-TCP RTU version, use to detect address offset and encoding of the MODBUS SLAVE |
39+
| Socket | Demo application that shows how to establish a TCP-IP connection with L-Net |
3940
| uMQTTbroker.pas | a simpliest MQTT broker, only capable of receiving publishing clients (need L-Net) |
4041
| uchunkmanager.pas | Server / Client component to send packages of data through a TCP-IP connection (need L-Net) |
4142
| uhtml.pas | HTML-DOM parser |

TCP_IP/Socket/Readme.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Socket
2+
3+
This demo shows how to use the L-Net TLTCPComponent component.
4+
5+
![](preview.png)
6+
7+
Features:
8+
- Listen to a port (Server)
9+
- Connect to a IP and port (Client)
10+
- Send as ASCII / Hex-Values
11+
- Server supports as many clients as wanted

TCP_IP/Socket/preview.png

77.8 KB
Loading

TCP_IP/Socket/project1.lpi

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<CONFIG>
3+
<ProjectOptions>
4+
<Version Value="12"/>
5+
<PathDelim Value="\"/>
6+
<General>
7+
<Flags>
8+
<CompatibilityMode Value="True"/>
9+
</Flags>
10+
<SessionStorage Value="InProjectDir"/>
11+
<Title Value="project1"/>
12+
<ResourceType Value="res"/>
13+
<UseXPManifest Value="True"/>
14+
</General>
15+
<i18n>
16+
<EnableI18N LFM="False"/>
17+
</i18n>
18+
<BuildModes Count="1">
19+
<Item1 Name="Default" Default="True"/>
20+
</BuildModes>
21+
<PublishOptions>
22+
<Version Value="2"/>
23+
</PublishOptions>
24+
<RunParams>
25+
<FormatVersion Value="2"/>
26+
<Modes Count="1">
27+
<Mode0 Name="default"/>
28+
</Modes>
29+
</RunParams>
30+
<RequiredPackages Count="2">
31+
<Item1>
32+
<PackageName Value="lnetvisual"/>
33+
</Item1>
34+
<Item2>
35+
<PackageName Value="LCL"/>
36+
</Item2>
37+
</RequiredPackages>
38+
<Units Count="2">
39+
<Unit0>
40+
<Filename Value="project1.lpr"/>
41+
<IsPartOfProject Value="True"/>
42+
</Unit0>
43+
<Unit1>
44+
<Filename Value="unit1.pas"/>
45+
<IsPartOfProject Value="True"/>
46+
<ComponentName Value="Form1"/>
47+
<HasResources Value="True"/>
48+
<ResourceBaseClass Value="Form"/>
49+
<UnitName Value="Unit1"/>
50+
</Unit1>
51+
</Units>
52+
</ProjectOptions>
53+
<CompilerOptions>
54+
<Version Value="11"/>
55+
<PathDelim Value="\"/>
56+
<Target>
57+
<Filename Value="project1"/>
58+
</Target>
59+
<SearchPaths>
60+
<IncludeFiles Value="$(ProjOutDir)"/>
61+
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
62+
</SearchPaths>
63+
<Linking>
64+
<Options>
65+
<Win32>
66+
<GraphicApplication Value="True"/>
67+
</Win32>
68+
</Options>
69+
</Linking>
70+
</CompilerOptions>
71+
<Debugging>
72+
<Exceptions Count="3">
73+
<Item1>
74+
<Name Value="EAbort"/>
75+
</Item1>
76+
<Item2>
77+
<Name Value="ECodetoolError"/>
78+
</Item2>
79+
<Item3>
80+
<Name Value="EFOpenError"/>
81+
</Item3>
82+
</Exceptions>
83+
</Debugging>
84+
</CONFIG>

TCP_IP/Socket/project1.lpr

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(******************************************************************************)
2+
(* *)
3+
(* Author : Uwe Schächterle (Corpsman) *)
4+
(* *)
5+
(* This file is part of Socket *)
6+
(* *)
7+
(* See the file license.md, located under: *)
8+
(* https://github.com/PascalCorpsman/Software_Licenses/blob/main/license.md *)
9+
(* for details about the license. *)
10+
(* *)
11+
(* It is not allowed to change or remove this text from any *)
12+
(* source file of the project. *)
13+
(* *)
14+
(******************************************************************************)
15+
Program project1;
16+
17+
{$MODE objfpc}{$H+}
18+
19+
Uses
20+
{$IFDEF UNIX}{$IFDEF UseCThreads}
21+
cthreads,
22+
{$ENDIF}{$ENDIF}
23+
Interfaces, // this includes the LCL widgetset
24+
Forms, lnetvisual, Unit1
25+
{ you can add units after this };
26+
27+
{$R *.res}
28+
29+
Begin
30+
RequireDerivedFormResource := True;
31+
Application.Initialize;
32+
Application.CreateForm(TForm1, Form1);
33+
Application.Run;
34+
End.
35+

TCP_IP/Socket/unit1.lfm

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
object Form1: TForm1
2+
Left = 340
3+
Height = 455
4+
Top = 113
5+
Width = 635
6+
Caption = 'Form1'
7+
ClientHeight = 455
8+
ClientWidth = 635
9+
Position = poScreenCenter
10+
LCLVersion = '3.99.0.0'
11+
Visible = True
12+
OnCloseQuery = FormCloseQuery
13+
OnCreate = FormCreate
14+
object Button1: TButton
15+
Left = 88
16+
Height = 25
17+
Top = 72
18+
Width = 75
19+
Caption = 'Connect'
20+
TabOrder = 0
21+
OnClick = Button1Click
22+
end
23+
object Edit1: TEdit
24+
Left = 88
25+
Height = 26
26+
Top = 8
27+
Width = 163
28+
TabOrder = 1
29+
Text = 'Edit1'
30+
end
31+
object Label1: TLabel
32+
Left = 8
33+
Height = 16
34+
Top = 16
35+
Width = 70
36+
Caption = 'IP Address :'
37+
ParentColor = False
38+
end
39+
object Label2: TLabel
40+
Left = 8
41+
Height = 16
42+
Top = 48
43+
Width = 32
44+
Caption = 'Port :'
45+
ParentColor = False
46+
end
47+
object Edit2: TEdit
48+
Left = 88
49+
Height = 26
50+
Top = 40
51+
Width = 163
52+
TabOrder = 2
53+
Text = 'Edit2'
54+
end
55+
object Button2: TButton
56+
Left = 176
57+
Height = 25
58+
Top = 72
59+
Width = 75
60+
Caption = 'Disconnect'
61+
Enabled = False
62+
TabOrder = 3
63+
OnClick = Button2Click
64+
end
65+
object Memo1: TMemo
66+
Left = 88
67+
Height = 192
68+
Top = 104
69+
Width = 528
70+
Anchors = [akTop, akLeft, akRight, akBottom]
71+
Lines.Strings = (
72+
'Memo1'
73+
)
74+
TabOrder = 4
75+
end
76+
object Button3: TButton
77+
Left = 541
78+
Height = 25
79+
Top = 304
80+
Width = 75
81+
Anchors = [akRight, akBottom]
82+
Caption = 'Clear'
83+
TabOrder = 5
84+
OnClick = Button3Click
85+
end
86+
object Button4: TButton
87+
Left = 541
88+
Height = 25
89+
Top = 380
90+
Width = 75
91+
Anchors = [akRight, akBottom]
92+
Caption = 'Send'
93+
TabOrder = 6
94+
OnClick = Button4Click
95+
end
96+
object CheckBox1: TCheckBox
97+
Left = 519
98+
Height = 22
99+
Top = 80
100+
Width = 111
101+
Anchors = [akTop, akRight]
102+
Caption = 'Receive as Hex'
103+
TabOrder = 7
104+
end
105+
object Button5: TButton
106+
Left = 88
107+
Height = 25
108+
Top = 416
109+
Width = 528
110+
Anchors = [akLeft, akRight, akBottom]
111+
Caption = 'Close'
112+
TabOrder = 8
113+
OnClick = Button5Click
114+
end
115+
object CheckBox3: TCheckBox
116+
Left = 399
117+
Height = 22
118+
Top = 352
119+
Width = 121
120+
Anchors = [akRight, akBottom]
121+
Caption = 'del text on send'
122+
Checked = True
123+
State = cbChecked
124+
TabOrder = 9
125+
end
126+
object CheckBox4: TCheckBox
127+
Left = 513
128+
Height = 22
129+
Top = 10
130+
Width = 120
131+
Anchors = [akTop, akRight]
132+
Caption = 'Show eventslog'
133+
TabOrder = 10
134+
end
135+
object Button6: TButton
136+
Left = 264
137+
Height = 25
138+
Top = 72
139+
Width = 75
140+
Caption = 'Listen'
141+
TabOrder = 11
142+
OnClick = Button6Click
143+
end
144+
object CheckBox5: TCheckBox
145+
Left = 397
146+
Height = 22
147+
Top = 328
148+
Width = 142
149+
Anchors = [akRight, akBottom]
150+
Caption = 'Add crt + lf on send'
151+
TabOrder = 12
152+
end
153+
object ComboBox1: TComboBox
154+
Left = 88
155+
Height = 28
156+
Top = 381
157+
Width = 444
158+
Anchors = [akLeft, akRight, akBottom]
159+
ItemHeight = 0
160+
TabOrder = 13
161+
Text = 'ComboBox1'
162+
end
163+
object Label3: TLabel
164+
Left = 8
165+
Height = 51
166+
Top = 322
167+
Width = 352
168+
Anchors = [akLeft, akBottom]
169+
Caption = '"#<value> " = send "number" (0..255)'#13#10'"##" = send "#"'#13#10'"#h<value> " = send "value" as hex (0 .. FF)'
170+
Font.Name = 'Courier New'
171+
ParentColor = False
172+
ParentFont = False
173+
end
174+
object ComboBox2: TComboBox
175+
Left = 541
176+
Height = 30
177+
Top = 345
178+
Width = 75
179+
Anchors = [akRight, akBottom]
180+
ItemHeight = 0
181+
Style = csDropDownList
182+
TabOrder = 14
183+
Visible = False
184+
end
185+
object LTCPComponent1: TLTCPComponent
186+
Port = 0
187+
OnReceive = LTCPComponent1Receive
188+
OnError = LTCPComponent1Error
189+
OnDisconnect = LTCPComponent1Disconnect
190+
OnConnect = LTCPComponent1Connect
191+
OnAccept = LTCPComponent1Accept
192+
Timeout = 0
193+
ReuseAddress = False
194+
Left = 56
195+
Top = 120
196+
end
197+
end

0 commit comments

Comments
 (0)