Sign in Join
Wiki copytemporary

conSock

About

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.

Author: Tito Hinostroza

License: GPL v3

Usage

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.

The connection model is similar to a Client-Server architecture, with the following rules:

Default IP for Client is 127.0.0.1. Default port for Client and Server is 80.

Frame structure

Library implements a Frame including:

Header part is small (fixed size 9 bytes) and has the following structure:

Units

The library contains 3 units:

To implement a basic connection, it's needed to create a client and server object.

Example

To implement a simple connection, it's needed to create a client part and a server part:

pascal
  //Set client
  client := TConSockClient.Create('127.0.0.1');
  client.OnFrameReady := @clientFrameReady;
  client.Connect;
  
  //Set server
  Server := TConSockServer.Create;
  Server.OnFrameReady := @ServerFrameReady;
  Server.Connect;

Event OnFrameReady is triggered every time a Frame is received.

The state of the connection can be read in the field client.state and in server.State. This state can be:

To send data from the client, we can use the following instruction:

pascal
  client.SendCommand($FF, 0, 0, sometext);

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.

For a complete code, check the sample projects.

Download

GitHub: https://github.com/t-edson/conSock


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.

Revision 2, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.