lNet

From Lazarus wiki
Revision as of 20:32, 16 January 2006 by Almindor (talk | contribs)
Jump to navigationJump to search

About

lNet or LightWeight Networking Library is a collection of classes and components to enable event-driven TCP or UDP networking. lNet is released under a modified LGPL license. (permits static linking)


The package consists of base lNet units library, lTelnet for telnet protocol, lFTP for ftp protocol and lNetComponents libraries for providing visual and non-visual components for networking.

These components were tested in Win32, Linux and FreeBSD. They should however run on any major platform supported by FPC. Homepage of the lNet base libraries is: http://members.chello.sk/ales

As of version 0.3 the package is only single-threaded. I've dropped multithreaded version and now use exclusivly LCL features to work.

Author

Ales Katona (User: Almindor)

License

Modified LGPL (read LICENSE and LICENSE.ADDON included in package).

Download

Change Log

  • Version 0.3.0 (2.4.0) 16.01.2006
  • Version 0.2.0 29.11.2005
  • Version 0.1.0 12.11.2005

Status

  • Base lNet TCP/UDP - stable
  • Telnet Client - experimental
  • FTP Client - experimental

Roadmap

  • Stress testing [always]
  • Addition of Telnet and FTP clients (experimental level) [0.3] (done)
  • Cementing of TCP/UDP API [0.3] (done)
  • Addition of Telnet and FTP servers (experimental level) [0.4]
  • Stabilazation of Telnet and FTP clients [0.4]
  • Addition of SMTP, HTTP components [0.4/0.5]
  • Addition of SSL, FTPS [0.6+]

Dependencies / System Requirements

  • Lazarus from SVN and FPC 2.0.2 (note: Latest lazarus is required because of LCL changes which also broke older lNet)

Status: Beta

Issues: Tested on Windows (WinXP), Linux (Kubuntu Breezy Badger) and FreeBSD 6.0.

Installation

  • In the lazarus/components directory, unzip the files from lnetpackage-<version>.zip file. The lNetpackage-<version> folder will be created.
  • Open lazarus
  • Open the package lnetpackage-<version>/lnetpackage.lpk with Component/Open package file (.lpk)
  • Click on Compile
  • Open the package lnetpackage-<version>/ide/lnetidepackage.lpk with Component/Open package file (.lpk)
  • Click on Install and answer 'Yes' when you are asked about Lazarus rebuilding. A new tab named 'lNet' will be created in the components palette.

Usage

TCP/UDP

Drop a TLTCPComponent or TLUDPComponent on a form. Assign OnAccept, OnError, OnReceive, OnConnect and OnDisconnect event handlers. Note that this is optional but in most cases required for functionality.

Client connection is initialized with the Connect call. Arguments are IP address/hostname and port respectivly. Non-blocking connect is used, this means that you DON'T know that you're connected until OnConnect event is fired.

Server connection is initialized with the Listen* call. Argument is port.

Note: address is a string representation of IP eg: '127.0.0.1' or a hostname like 'localhost'.

Sending data to the other side is accomplished with the Send/SendMessage method.

Events of TLNetComponent class.

  • OnError - this event is fired whenever a connection error occurs. If no handler is assigned an excepion with "msg" is raised. Arguments are: msg - contains string and numerical representation of error message formatted in native encoding or UTF8 (depending on ForceUTF8 property). aSocket is the socket at which the error occured, nil means that the error is not a socket specific one.
  • OnConnect - This event is fired when the client succesfuly connects. aSocket is the socket which connected. It should serve as the "start" point for clients.
  • OnAccept - this event is fired whenever a connection is accepted on a server. If no handler is assigned nothing is done. aSocket contains the socket which accepted the connection.
  • OnDisconnect - this event is fired whenever a connection is lost. If no handler is assigned nothing is done. aSocket contains the socket which got disconnected.
  • OnReceive - This event is fired whenever new data is ready to be received. If no handler is assigned nothing is done, but a system buffer fill may happen which will in turn fire an OnError event. aSocket is the socket at which the data got received. Data is read by Get/GetMessage method.
  • OnCanSend - This event is fired whenever new data can be sent again on a socket. It can be used to automate sending of big chunks. aSocket is socket on which send can be called.

API CHANGES:*

0.1 to 0.2 There have been some API changes from 0.1 to 0.2. These were required and should improve the usability of packages. I know API changes are always a PITA but I'll try to keep them minimal from now on. Version 0.3 will be the first beta from which API will remain unchanged (only adding new stuff will be possible).

  • OnRecieve() changed to OnReceive()
  • Accept() changed to Listen()
  • All events' arguments changed. SocketNumber (int) got changed into aSocket(TLSocket) because of logical and speed reasons

0.2 to 0.3 Added OnCanSend and OnConnect. Connect is now non-blocking. Removed buffersize and maxmsgs. Buffersize is no longer required because no internal buffer is used.