Using IdTcpClient for logging data (Lazarus/Fpc) - Printable Version +- Atozed Forums (https://www.atozed.com/forums) +-- Forum: Indy (https://www.atozed.com/forums/forum-8.html) +--- Forum: Indy General Discussion (https://www.atozed.com/forums/forum-9.html) +--- Thread: Using IdTcpClient for logging data (Lazarus/Fpc) (/thread-737.html) |
Using IdTcpClient for logging data (Lazarus/Fpc) - BosseB - 10-13-2018 I need to write a small utility for receiving logging data from an embedded WiFi device. The device (based on ESP8266) is programmed to work as a TCP<=>Serial bridge for channeling data between a data collection unit and a network connected master (can be a PC program or an Android App using TCP socket communications). We have problems in certain operating modes with the device and so I need to check the data handled by the device. Dropped bytes is a killer here... So I added two TCP servers to the device each listening on different ports and dedicated to log data sent to and from the serial port of the device. Every time there is any data in either of these sources it will be sent to the logging client in addition to the relaying destination. Now I need to add two instances of a "logging client" to my configuration program (written with Lazarus/FPC and using the indylaz package components) and the plan is to do this as follows: - Write a TCP logging class I can instantiate twice for the two logging directions - Each class instance shall connect to the server on one of the two ports dedicated for logging - While connected it shall wait for incoming data and dump all received bytes to a log file. - The running count of the received bytes shall be reported to the main application for display (event function) In order to do the above I probably need to use a threaded approach since I must keep the application live and responsive. But I have not succeeded to find any good example to start from where the TCP client is threaded and does not send anything at all by itself, it shall just receive and write to disk whatever comes along. And generate an event with the current byte count. Any suggestions on how this can be accomplished? This is as far as I have come as of now: Code: type Usage in main form: Code: procedure TfrmCommTest.FormCreate(Sender: TObject); The data received (into a TIdBytes container) is sent to the main thread in the event function if defined to be stored into a file (file save not shown above). Do I need some exception handling inside the Execute method? |