ConSock

This is an old revision of ConSock, edited by Alextp at . The current revision is 140001.

/* Download */

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 communicates 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:

  //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:

  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