Sockets/fr

From Lazarus wiki
Revision as of 11:08, 3 August 2011 by Chronos (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

English (en) español (es) français (fr) slovenčina (sk)

A propos

Sockets est un paquet de licence LGPL-modifiée pour Lazarus. Il définit le composant TSocketClient pour connecter les applications aux connecteurs(sockets) de serveur générique sur les reseaux TCP/IP.


Le téléchargement contient les fichiers des composants Pascal, Le fichier paquet de Lazarus, les fichiers ressource et les fichiers texte avec la licence modifiée LGPL.

Ce composant à été désigné pour les applications en exécution sur les plateformes Linux et Win32.

Auteur

Antonio d'Avino

Licence

LGPL Modifiée(Lire COPYING.modifiedLGPL et COPYING.LGPL inclu dans le paquet).

Téléchargement

La dernière réalisation stable peut être trouvée sur la page des fichier CCR de Lazarus ou sur les pages web de l'auteur http://infoconsult.homelinux.net.

  • Maintenant vous pouvez trouver les connecteurs(sockets) ici.

historique des modifications

  • Version 0.2.0 2005/06/01

Feuille de route

  • Implémentation du mode asynchrone dans les opérations d'écriture.
  • Ajout de la classe TSocketServer au pacquet

Dépendances / Configuration requise

  • Lazarus 0.9.6 (FPC 1.9.8)

Statut: Beta

Issues: Testé sur Windows (Win2K) et Linux (Mdk 10.1).

Installation

  • In the lazarus/components directory, untar (unzip) the files from sockets-laz-package-<version>.tar.gz file. The sockets folder will be created.
  • Open lazarus
  • Open the package sockets_laz.lpk with Component/Open package file (.lpk)
  • (Click on Compile only if you don't want to install the component into the IDE)
  • Click on Install and answer 'Yes' when you are asked about Lazarus rebuilding. A new tab named 'Sockets' will be created in the components palette.

Note for Win32 users: In case you experience some difficults in compiling the Pascal files, you may need to add the following path: <some-drive>:<some-path>\lazarus\lcl\units\i386\win32 (ie: c:\programs\lazarus\lcl\units\i386\win32) to the 'Other unit files ...' in 'Paths' tab of 'Compiler Options' of the lazarus package manager window.

Usage

Drop a TSocketClient component on a form, for any different client socket connections your application needs. Mandatory property of this component you have to set are:

  • Host : the TCP/IP address or the URL of the PC where the server sockets you want to connect to is running;
  • Port : the TCP/IP port on wich the server process is listening;

Optional properties you may set are:

  • DosLf : If set to 'True', a CR (0x0D) is prepend to LF (0x0A) when a writeLineLf procedure is executed (see forward).
  • ReadCharsThereshold : the number of characters read from channel before a OnReadChars event is triggered (see forward). 0 is equivalent to 1.

Now you can set to 'True' the property Active for opening the channel. An exception is raised if connection fails (host unreachable, no server process listening on port, network errors). The connection is closed setting 'False' the active property. Also, you can test the Active property to verify if connection status is ON (the closing of the connection by the server side set false this property).

Public methods of the TSocketClient class.

  • function bufferChars : Integer. It returns the number of chars received from the server process through the channel and available for reading.
  • function getBuffer (var buffer: String) : Integer. This function copy the chars from internal buffer of component into the parameter string 'buffer'. The number of characters copied is returned and the internal buffer is empty.
  • function readLine (var buffer: String) : Boolean. The characters in internal buffer are copied into the parameter string 'buffer', upto, but not including, the first LF (0x0A9) character occurrence. Any CR characters (0x0D) are discarded.

If a complete line can be copied, the function returns true. If not any LF char is encountered, the whole internal buffer is copied into the 'buffer' parameter and the function returns false.

Note: the pending content in internal buffer is available also when the connection is closed. It will be lost only when the connection is reopen.

  • function writeChar (buffer : Char ) : ShortInt. This function write a single char on channel, returning 0 in case of success or a value less than 0 if it fails.
  • function writeLine (buffer : String) : ShortInt. The content of parameter buffer is sent to server. The function returns 0 in case of success or a value less than 0 if it fails.
  • function writeLineLf (buffer : String) : ShortInt. Same of writeLine function, but a LF char (0x0A) is appended (a couple of CR/LF, if property DOSLf is true). The function returns 0 in case of success or a value less than 0 if it fails.

Note: at this moment, the write methods of the class are not asynchronous, so they may be blocking for your application in case of failing. This will be fixed in next release.

Events of TSocketClient class.

  • OnBufferFull : this event is triggered when the internal buffer is full. No others characters are received from channel until characters are read from internal buffer.
  • OnEndOfLineReceive : this event occurs where a LF character (0x0A) is received from server.
  • OnReadChars : this event is triggered when a number of at least ReadCharsThereshold is pending in internal buffer.
  • OnStateChange : this event occurs any time the Active property change its value.