TTcpClient problem cant recieve anything

Hey, Im having a problem where I connect to 127.0.0.1 on port 666 using the function in button1 then onconnect i get a message saying it connects just fine. Now button2 sends the character 'F' and its supposed to get a bunch of data back. Well the TcpClient1Recieve function never gets called... why?

if i do
telnet 127.0.0.1 666
F
GOT:F

it works just fine.

Now what am i doing wrong? and please dont tell me to work around it by using indy or whatever else.
Tom

procedure TForm1.Button1Click(Sender: TObject);
begin
TcpClient1.Connect
end;

procedure TForm1.TcpClient1Receive(Sender: TObject; Buf: PAnsiChar;
  var DataLen: Integer);
begin
       showmessage('GOTDATABACK');
end;

procedure TForm1.TcpClient1Connect(Sender: TObject);
begin
          ShowMessage('Connected');
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
        TcpClient1.Sendln('F');
end;
T0maszAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

pcsentinelCommented:
var
  lResult: string;
begin
  TcpClient1.Sendln('F');
  lResult:=TcpClient1.ReadLn;
end;
0
T0maszAuthor Commented:
I want it to be read as data comes in (onevent) not have to wait after sending something each time

Tom
0
T0maszAuthor Commented:
oh and tcpclient1 doesnt have a readln function
0
pcsentinelCommented:
The way indy works is that a client invokes an action on a server, because of this the client has no direct way of activating when it receives data. You can get round this by using a timer

set up a timer, say 500ms and then on the timer do

this if for INDY 9

var
 lMsg: string;
begin
  Timer1.Enabled:=false;
  lMsg:=idTCPClient1.ReadLn;
  if lMsg<>'' then
  begin
   {process your message here}
  end;
  Timer1.Enabled:=true;
end;



for Indy 10 which I haven't got installed I think you need


var
 lMsg: string;
begin
  Timer1.Enabled:=false;
  lMsg:=idTCPClient1.IOHandler.ReadLn;
  if lMsg<>'' then
  begin
   {process your message here}
  end;
  Timer1.Enabled:=true;
end;

regards
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MainiacfreakusCommented:
try this:

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  If idtcpclient1.Connected then Begin
    IdTCPClient1.CheckForGracefulDisconnect(True);
    If not IdTCPClient1.IOHandler.InputBufferIsEmpty then ShowMessage(IdTCPClient1.IOHandler.ReadLn);
  End;
end;

NB: It uses a timer event to check if there is data to read, if there is, it reads it...

Mainiacfreakus
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.