This works for me, it depends if you are in lock mode or not:
unit Unit11; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Sockets, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, StdCtrls; type TForm1 = class(TForm) IdTCPClient1: TIdTCPClient; TcpClient1: TTcpClient; Memo1: TMemo; procedure TcpClient1Connect(Sender: TObject); procedure TcpClient1Receive(Sender: TObject; Buf: PAnsiChar; var DataLen: Integer); procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); begin TcpClient1.BlockMode := bmBlocking; TcpClient1.RemoteHost := 'www.google.com'; TcpClient1.RemotePort := '80'; TcpClient1.Connect; end; procedure TForm1.TcpClient1Connect(Sender: TObject); var s : string; begin memo1.Lines.Add('connected'); TcpClient1.Sendln('GET /'); s := TcpClient1.Receiveln; memo1.Lines.Add(S); end; end.
EDIT
here is a real world example with an RTSP server (in this case you are in this case) I used Indy IdTcpClient
unit Unit11; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, Sockets, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, StdCtrls; type TForm1 = class(TForm) Memo1: TMemo; Client: TIdTCPClient; procedure FormCreate(Sender: TObject); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} procedure TForm1.FormCreate(Sender: TObject); var s : string; begin Client.Host := 'v5.cache6.c.youtube.com'; Client.Port := 554; Client.Connect; Client.IOHandler.Writeln('OPTIONS * RTSP/1.0'); Client.IOHandler.Writeln('CSeq: 1'); Client.IOHandler.Writeln(''); s := Client.IOHandler.ReadLn; Memo1.Lines.Add(s); s := Client.IOHandler.ReadLn; Memo1.Lines.Add(s); end; end.
source share