![]() |
Need to time arrival of TCP socket data, how? - 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: Need to time arrival of TCP socket data, how? (/thread-806.html) |
Need to time arrival of TCP socket data, how? - BosseB - 11-09-2018 I am troubleshooting a WiFi UART<=>TCP socket bridge device and I need to verify the arrival times of packets sent via the UART input to the device at the TCP client end. So in this case I will be sending packets of data via the serial link to the device starting at exactly 1 s intervals. The packets are rather short, basically date/time strings in pure ASCII like "20181109" and "13:46:17" My test strings start with STX and end with ETX bytes (0x02 and 0x03 respectively). Each second the date and time packets are sent back-to-back and then nothing until the next second. Speed is 38400 baud. I am using FreePascal 3.0.4 and Lazarus 1.8.0 with the indylaz package installed on a Windows 7 x64 laptop. Since the data arrive at times the client does not control and indy is blocking I have trouble implementing this checking utility... What I need is: - Connect the TIdTCPClient object to the bridge device on port 2101 (this is not a problem) - Somehow start listening for incoming data - When a packet has arrived transfer it to the main application for timing and logging purposes. Probably this needs some kind of thread or a loop with Application.Processmessages, but I am not sure how to approach this... Any advice available? I have already implemented a configuration utility for the same WiFi bridge device using Indy, but that only had to deal with handshakes with a command sent from the client and a response being sent back almost instantly. These commands are not started with STX but ended with ETX. So this is implemented as follows (excerpt from config utility code), hopefully I could re-use some of that code: Code: implementation In the main application the FOnComm procedure is implemented as follows to show incoming data: Code: procedure TfrmMainConfig.OnComm(Sender: TObject; Msg: AnsiString); As this test is aimed at nailing some randomly occurring timing problems I need to accurately time the arrival of the packets to see if there is any problem in the bridge device. I want to log any time deviation from the 1000 ms mark so see what is going on. The real consumer of the data sent trough the bridge is an Android App and I suspect that we might be dealing with a problem in that, but I have to prove it. Different developers.... RE: Need to time arrival of TCP socket data, how? - kudzu - 11-09-2018 ProcessMessages wont help. A thread sounds like what might work best in your scenario. RE: Need to time arrival of TCP socket data, how? - BosseB - 11-09-2018 And this is what gets me stuck every time I encounter blocking devices.... I never seem able to make any working code using threads. That is why my config code shown above looks like it does... Do you have any idea how that can be done in detail? RE: Need to time arrival of TCP socket data, how? - kudzu - 11-09-2018 This is standard threading. 1) Create a thread. 2) Create and connect socket 3) Read and wait for data 4) Synchronize data to main thread. RE: Need to time arrival of TCP socket data, how? - BosseB - 11-11-2018 Done and working. Used this webpage as source of ideas. Synchronize did the trick. |