Skullcode 0 Posted August 23, 2020 i am using Twsocket as a TcpClient to communicate with a tcpserver the server sends a packet in loop that should be received by the connected Client but Twsocket doesnt read all packets that sent by the server it reads one and miss another and read again and miss one again . is it a normal behavior by Twsocket ? i tested with TidtcpClient and it reads all packets normally no matter what Share this post Link to post
Angus Robertson 574 Posted August 24, 2020 A properly written ICS application will never lose any data with TCP. Try receiving the data with the OverbyteIcsIpStmLogTst.dpr sample, Angus Share this post Link to post
Fr0sT.Brutal 900 Posted August 24, 2020 Because of its async nature, reading from TWSocket is somewhat more complex than "while Read > 0 do". Just check provided demos for the sample Share this post Link to post
FPiette 383 Posted August 24, 2020 15 hours ago, Skullcode said: Twsocket doesnt read all packets that sent by the server it reads one and miss another and read again and miss one again I think since TWSocket exists for 24 years, if this bug exists, we should have already seen it. I think is is likely the code you wrote which is wrong. But I can tell... 1) Could you please show relevant code 2) How do you know that it is no a sever issue 3) Before writing you own code, check with one of the samples Share this post Link to post
Skullcode 0 Posted August 27, 2020 On 8/24/2020 at 3:30 PM, FPiette said: I think since TWSocket exists for 24 years, if this bug exists, we should have already seen it. I think is is likely the code you wrote which is wrong. But I can tell... 1) Could you please show relevant code 2) How do you know that it is no a sever issue 3) Before writing you own code, check with one of the samples The server is built with Java, i dont think that the issue within the server sense i already have another client in java works properly. also tested in Delphi Tidtcpclient and it works Fine without missing packets. in Twsocket i am not doing anything special , i have just placed Twsocket then ondataAvailable Event i read the data procedure TForm1.asockDataAvailable(Sender: TObject; ErrCode: Word); var datastr : string; begin datastr := asock.ReceiveStrW(CP_UTF8); Memo1.lines.add(datastr); end; The server is using CRLF for each packet maybe this is an issue ? Share this post Link to post
Angus Robertson 574 Posted August 27, 2020 (edited) If you look at any ICS components or samples that receive data, you see that you need to loop within the event to receive data with that function, you may get six bytes first time, 29K next time, loop until nothing more is returned. If you receive a string, it may be a partial line, so you need to buffer it until the a full line is available. ICS also has line mode that makes sure you receive full lines, but you may lose data if the last line does include CRLF. Also, you can not read UTF8 data reliably like this, because you may get a partial character with the first read. You need to wait until you have a line, then convert from ANSI to Unicode. If you used the OverbyteIcsIpStmLogTst.dpr sample I suggested, none of this would be an issue, it's all done for you. Angus Edited August 27, 2020 by Angus Robertson 1 Share this post Link to post