Search the Community
Showing results for tags 'tidtcpclient'.
Found 1 result
-
Hello, I am using Delphi 10.3.2, Indy version: 10.6.2.5366 (default coming with Delphi). There is a gpsd daemon running on a Raspberry Pi. It is broadcasting some json strings over TCP:2947 - I can successfully establish a connection using TIdTCPClient. There is no data incoming after connection. - Send command to stream my client these json strings after connection. There is no data incoming after sending command. Memo output: Memo1 Connecting to 192.168.1.90. Connected. On the other hand; - Using Putty, I instantly get initial greeting json string right after connection without sending anything. - if I send command to stream I instantly get json string replies. Putty terminal output: {"class":"VERSION","release":"3.17","rev":"3.17","proto_major":3,"proto_minor":12} ?WATCH={"enable":true,"json":true} {"class":"DEVICES","devices":[{"class":"DEVICE","path":"/dev/ttyS0","activated":"2019-08-31T15:56:43.607Z","native":0,"bps":9600,"parity":"N","stopbits":1,"cycle":1.00}]} {"class":"WATCH","enable":true,"json":true,"nmea":false,"raw":0,"scaled":false,"timing":false,"split24":false,"pps":false} My current test code: unit uMain; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, Vcl.ExtCtrls, Vcl.StdCtrls; type TForm2 = class(TForm) IdTCPClient1: TIdTCPClient; Memo1: TMemo; Timer1: TTimer; Button1: TButton; procedure IdTCPClient1Connected(Sender: TObject); procedure IdTCPClient1Disconnected(Sender: TObject); procedure IdTCPClient1Status(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string); procedure Timer1Timer(Sender: TObject); procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure FormDestroy(Sender: TObject); private { Private declarations } SentStreamCommand: Boolean; public { Public declarations } end; var Form2: TForm2; implementation {$R *.dfm} procedure TForm2.Button1Click(Sender: TObject); begin if Button1.Tag <> 0 then begin IdTCPClient1.Disconnect(); Button1.Caption := 'Connect'; Button1.Tag := 0; end else begin IdTCPClient1.Connect('192.168.1.90', 2947); Button1.Caption := 'Disconnect'; Button1.Tag := 1; end; end; procedure TForm2.FormCreate(Sender: TObject); begin Timer1.Enabled := False; SentStreamCommand := False; end; procedure TForm2.FormDestroy(Sender: TObject); begin if IdTCPClient1.Connected then IdTCPClient1.Disconnect(False); end; procedure TForm2.IdTCPClient1Connected(Sender: TObject); begin Timer1.Enabled := True; end; procedure TForm2.IdTCPClient1Disconnected(Sender: TObject); begin Timer1.Enabled := False; end; procedure TForm2.IdTCPClient1Status(ASender: TObject; const AStatus: TIdStatus; const AStatusText: string); begin Memo1.Lines.Add(AStatusText); end; procedure TForm2.Timer1Timer(Sender: TObject); var ReceivedText: string; begin Timer1.Enabled := False; try with IdTCPClient1 do begin if not Connected then Exit(); // read any data in if IOHandler.InputBufferIsEmpty then begin IOHandler.CheckForDataOnSource(0); IOHandler.CheckForDisconnect; if IOHandler.InputBufferIsEmpty then Exit(); ReceivedText := IOHandler.AllData(); if ReceivedText <> EmptyStr then Memo1.Lines.Add(ReceivedText); end; // if not already, send streaming command if not SentStreamCommand then begin IdTCPClient1.IOHandler.WriteLn('?WATCH={"enable":true,"json":true}'); SentStreamCommand := True; Exit(); end; end; finally if IdTCPClient1.Connected then Timer1.Enabled := True; end; end; end. I would like to understand what I am doing wrong. My main purpose is to read each json string separately as they are incoming one per line. I appreciate any help, please. Thanks & regards, Ertan