[Lazarus] lnet sockets

Bernd prof7bit at gmail.com
Wed Oct 24 15:29:58 CEST 2012

2012/10/24 Antonio Fortuny <a.fortuny at sitasoftware.lu>:

>> Its all meant to be used completely asynchronously. The easiest way
>> would be to start a TTimer and when the timer event fires check
>> whether you have received an answer already or otherwise close the
>> connection.
> Yeah. Got the same with my Sleep loop.
> Not very clean.

You can also run the lnet in some kind of blocking mode, for this you
need to assign a different eventer. (select eventer or epoll eventer
or TBestEventer to automatically chooe the most appropriate eventer)
and then you make a separate thread that will just call the CallAction
method in an infinite loop. CallAction will block until an event
happens and then you call it again and again. Note that with this
approach all your lnet event methods will be called from within this
event thread.

You can either use only one eventer (and only one event thread) for
all your sockets (if you have multiple connections going on
simultanously)  or alternatively you could also create a new separate
eventer and a new separate thread for each new connection. The latter
will give you the same functionality as with blocking sockets.

The eventer has a timeout property, if you set it to a non zero value
in milliseconds the callaction call will block only up to that amount
of time, this way you can also count time and trigger actions on
timeout in the eventer thread (and if you make one separate eventer
thread for every connection you can easily achieve what you are trying
to do).

More information about the Lazarus mailing list