TCP客户端未从RTSP服务器接收响应

Jer*_*dge 6 sockets delphi rtsp tcp-ip delphi-xe2

在Delphi XE2中,我使用该TTCPClient组件与RTSP服务器通信.在试验和错误没有得到服务器的响应后,我切换项目通过端口​​80发送HTTP请求(而不是RTSP的554)并尝试向网站发送请求(特别是www.google.com).我还没有得到任何回应.

TTCPClient在主窗体(Form1)上调用了一个组件Client,一个TMemo名为control 的控件Log,一个TEdit名为control 的控件txtHost和一个TBitBtn控件.这是代码的相关部分:

连接到服务器

procedure TForm1.BitBtn1Click(Sender: TObject);
begin
  if Client.Active then Client.Disconnect;
  Client.RemoteHost:= txtHost.Text;
  Client.RemotePort:= '80'; // '554';
  Client.Connect;
end;
Run Code Online (Sandbox Code Playgroud)

OnConnect事件处理程序(HTTP)

procedure TForm1.ClientConnect(Sender: TObject);
var
  S: String;
begin
  Client.Sendln('GET / HTTP/1.0');
  Client.SendLn('');
end;
Run Code Online (Sandbox Code Playgroud)

OnConnect事件处理程序(RTSP)

procedure TForm1.ClientConnect(Sender: TObject);
var
  S: String;
begin
  Client.SendLn('OPTIONS * RTSP/1.0');
  Client.SendLn('CSeq:0');
  Client.SendLn('');
end;
Run Code Online (Sandbox Code Playgroud)

OnReceive事件处理程序

procedure TForm1.ClientReceive(Sender: TObject; Buf: PAnsiChar;
  var DataLen: Integer);
var
  S, R: String;
begin
  S:= Client.Receiveln;
  while S <> '' do begin
    R:= R+ S;
    S:= Client.Receiveln;
  end;
  Log.Lines.Append('> RECEIVED ' + R);
end;
Run Code Online (Sandbox Code Playgroud)

OnError事件处理程序

procedure TForm1.ClientError(Sender: TObject; SocketError: Integer);
begin
  Log.Lines.Append('> ERROR '+IntToStr(SocketError));
end;
Run Code Online (Sandbox Code Playgroud)

OnReceive永远不会调用该事件,任何从我连接的服务器都没有回来.

我在这做错了什么?

参考

这些是我引用的一些链接:

我正在使用的相机是 Grandstream GXV3601LL

UPDATE

我已经得出结论,问题出在RTSP服务器上,并在Grandstream的网站上的论坛上提出了一个问题.该代码可与其他服务器连接一起使用.

who*_*ddy 6

这对我有用,这取决于你是否处于阻止模式:

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.
Run Code Online (Sandbox Code Playgroud)

编辑

这是一个带有RTSP服务器的实际例子(在本例中为youtube)我使用的是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.
Run Code Online (Sandbox Code Playgroud)