Jump to content

@rturas

Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral
  1. @rturas

    Indy TCP client

    Hello Remy, Thank you so much for the explanation. It is highly appreciated.
  2. @rturas

    Indy TCP client

    Hello, I am trying to create the app that sends a messages to the server and gets back an answer from it in a thread on the regular time intervals. Request contains 6 bytes, answer should be 65 bytes. My code looks like that: //TThread Constructor inherited Create(True); TCPClient := TIdTCPClient.Create; TCPClient.Host := AHost; TCPClient.Port := APort; TCPClient.ConnectTimeout := 5000; TCPClient.ReuseSocket := rsTrue; //TThread Execute procedure SetLength(wBuffer, 6); //Here i do write some bytes SetLength(rBuffer, 65); while not Terminated do begin try TCPClient.Connect; except on E: Exception do begin TThread.Queue(nil, procedure begin Form2.mmo1.Lines.Add('Exception: ' + e.Message); end); for i := 1 to 5 do begin if not Terminated then Sleep(1000); end; Continue; end; end; Reading := False; i := 1; while not Terminated do begin if not Reading then begin Reading := True; TCPClient.IOHandler.Write(wBuffer, 6, 0); end; try if Reading then begin if TCPClient.IOHandler.CheckForDataOnSource(100) then begin TCPClient.IOHandler.ReadBytes(rBuffer, 65, False); TThread.Queue(nil, procedure begin Form2.mmo1.Lines.Add('Buffer size: ' + IntToStr(TCPClient.IOHandler.InputBuffer.Size)); end); if not TCPClient.IOHandler.InputBufferIsEmpty then begin //I do some stuff here i := i +1; Reading := False; Sleep(1000); end; end; end; except on E: Exception do begin TThread.Queue(nil, procedure begin Form2.mmo1.Lines.Add('Reading exception: ' + e.Message); end); Sleep(1000); Continue; end; end; end; end; I do get only one line in the memo: Buffer size: 0 What am i doing wrong? How can i fix it? Thank you in advance.
×