Sign in Join
Wiki copytemporary

conSock: what changed

Revision 1 to 2. Removed lines have a minus sign; added lines have a plus sign.

OldNewLine
1-## Contents
2-
3- * 1 About
4- * 2 Usage
5- * 2.1 Frame structure
6- * 2.2 Units
7- * 2.3 Example
8- * 3 Download
9-
101## About
112
12-conSock is a Lazarus library that implements TCP/IP connections, in Client-Server mode, using sockets. It is based on [[Synapse]]. Tested only in Windows.
3+conSock is a Lazarus library that implements TCP/IP connections, in Client-Server mode, using sockets. It is based on [[Synapse]]. Tested only in Windows.
134
14-Author: Tito Hinostroza
5+Author: Tito Hinostroza
156
16-License: GPL v3
7+License: GPL v3
178
189## Usage
1910
20-Using the library is easy because it presents objects that communicate using events. At the low level the objects are implemented using blocking sockets and threads.
11+Using the library is easy because it presents objects that communicate using events. At the low level the objects are implemented using blocking sockets and threads.
2112
22-The connection model is similar to a Client-Server architecture, with the following rules:
13+The connection model is similar to a Client-Server architecture, with the following rules:
2314
24- * To implement a communication, there must be one Client and one Server part.
25- * Client part must be set with the IP address of the Server part. Server doesn't need to be set.
26- * Server part can connect only to one client. If there are several clients connecting to the same server, only the first will be accepted.
27- * Once the connection is established, only client can start the communication. The server can respond only to a client request.
28- * All communications are implemented using the same Frame structure.
15+- To implement a communication, there must be one Client and one Server part.
16+- Client part must be set with the IP address of the Server part. Server doesn't need to be set.
17+- Server part can connect only to one client. If there are several clients connecting to the same server, only the first will be accepted.
18+- Once the connection is established, only client can start the communication. The server can respond only to a client request.
19+- All communications are implemented using the same Frame structure.
2920
30-Default IP for Client is 127.0.0.1. Default port for Client and Server is 80.
21+Default IP for Client is 127.0.0.1. Default port for Client and Server is 80.
3122
3223### Frame structure
3324
34-Library implements a Frame including:
25+Library implements a Frame including:
3526
36- * Header part: 9 bytes size
37- * Data part: Optional. Can be as big as 16777215 bytes
27+- Header part: 9 bytes size
28+- Data part: Optional. Can be as big as 16777215 bytes
3829
39-Header part is small (fixed size 9 bytes) and has the following structure:
30+Header part is small (fixed size 9 bytes) and has the following structure:
4031
41- * 1 byte: Header ID. Header ID is always the hexadecimal value $0F, and is a way to identify the start of a frame.
42- * 3 bytes: Data part size. The "Data part size" indicates the size of the "Data part".
43- * 1 byte: Command. User can send any command in the frame field "Command". But the values $03 and $83 are reserved to internal dialog of the protocol.
44- * 2 bytes: X parameter. Parameters X and Y can be used to send additional information for a command.
45- * 2 bytes: Y parameter.
32+- 1 byte: Header ID. Header ID is always the hexadecimal value \$0F, and is a way to identify the start of a frame.
33+- 3 bytes: Data part size. The "Data part size" indicates the size of the "Data part".
34+- 1 byte: Command. User can send any command in the frame field "Command". But the values \$03 and \$83 are reserved to internal dialog of the protocol.
35+- 2 bytes: X parameter. Parameters X and Y can be used to send additional information for a command.
36+- 2 bytes: Y parameter.
4637
4738### Units
4839
49-The library contains 3 units:
40+The library contains 3 units:
5041
51- * conSockFrames.pas - Defines the protocol and the routines to code/decode the Frame packet.
52- * conSockClient.pas - Defines the base client object TConSockClient.
53- * conSockServer.pas - Defines the base server object TConSockServer.
42+- conSockFrames.pas - Defines the protocol and the routines to code/decode the Frame packet.
43+- conSockClient.pas - Defines the base client object TConSockClient.
44+- conSockServer.pas - Defines the base server object TConSockServer.
5445
55-To implement a basic connection, it's needed to create a client and server object.
46+To implement a basic connection, it's needed to create a client and server object.
5647
57- * Client Part - Modelled with the object TConSockClient.
58- * Server Part - Modelled with the object TConSockServer.
48+- Client Part - Modelled with the object TConSockClient.
49+- Server Part - Modelled with the object TConSockServer.
5950
6051### Example
6152
62-To implement a simple connection, it's needed to create a client part and a server part:
63-```
64-//Set client
65- client := TConSockClient.Create('127.0.0.1');
66- client.OnFrameReady := @clientFrameReady;
67- client.Connect;
68-
69- //Set server
70- Server := TConSockServer.Create;
71- Server.OnFrameReady := @ServerFrameReady;
72- Server.Connect;
53+To implement a simple connection, it's needed to create a client part and a server part:
54+
55+``` pascal
56+ //Set client
57+ client := TConSockClient.Create('127.0.0.1');
58+ client.OnFrameReady := @clientFrameReady;
59+ client.Connect;
60+
61+ //Set server
62+ Server := TConSockServer.Create;
63+ Server.OnFrameReady := @ServerFrameReady;
64+ Server.Connect;
7365```
7466
75-Event OnFrameReady is triggered every time a Frame is received.
67+Event OnFrameReady is triggered every time a Frame is received.
7668
77-The state of the connection can be read in the field client.state and in server.State. This state can be:
69+The state of the connection can be read in the field client.state and in server.State. This state can be:
7870
79- * cecCONNECTING
80- * cecCONNECTED
81- * cecSTOPPED
82- * cecDEAD
71+- cecCONNECTING
72+- cecCONNECTED
73+- cecSTOPPED
74+- cecDEAD
8375
84-To send data from the client, we can use the following instruction:
85-```
86-client.SendCommand($FF, 0, 0, sometext);
76+To send data from the client, we can use the following instruction:
77+
78+``` pascal
79+ client.SendCommand($FF, 0, 0, sometext);
8780```
8881
89-Where $FF represents some command, and "sometext" represents the data part of the command. We can use different commands number, except the values $03 and $83 that are reserved for the library.
82+Where \$FF represents some command, and "sometext" represents the data part of the command. We can use different commands number, except the values \$03 and \$83 that are reserved for the library.
9083
91-For a complete code, check the sample projects.
84+For a complete code, check the sample projects.
9285
9386## Download
9487
9588GitHub: <https://github.com/t-edson/conSock>
9689
9790---
98-*From the Free Pascal wiki, page "conSock", as the Internet Archive kept it on 2023-09-24. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
91+*From the Free Pascal wiki, page "conSock", as it stood on 2020-10-07 after a change by Bart, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).*
92+Category: Lazarus
93+Category: Networking

Back to history