在Delphi XE2中,我使用TTCPClient组件与RTSP服务器通信.在试验和错误没有得到服务器的响应后,我切换项目通过端口80发送HTTP请求(而不是RTSP的554)并尝试向网站发送请求(特别是www.google.com).我还没有得到任何回应.
我在主窗体(Form1)上有一个名为Client的TTCPClient组件,一个名为Log的TMemo控件,一个名为txtHost的TEdit控件和一个TBitBtn控件.这是代码的相关部分:
连接到服务器
- procedure TForm1.BitBtn1Click(Sender: TObject);
- begin
- if Client.Active then Client.Disconnect;
- Client.RemoteHost:= txtHost.Text;
- Client.RemotePort:= '80'; // '554';
- Client.Connect;
- end;
OnConnect事件处理程序(HTTP)
- procedure TForm1.ClientConnect(Sender: TObject);
- var
- S: String;
- begin
- Client.Sendln('GET / HTTP/1.0');
- Client.SendLn('');
- end;
OnConnect事件处理程序(RTSP)
- procedure TForm1.ClientConnect(Sender: TObject);
- var
- S: String;
- begin
- Client.SendLn('OPTIONS * RTSP/1.0');
- Client.SendLn('CSeq:0');
- Client.SendLn('');
- end;
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;
OnError事件处理程序
- procedure TForm1.ClientError(Sender: TObject; SocketError: Integer);
- begin
- Log.Lines.Append('> ERROR '+IntToStr(SocketError));
- end;
永远不会调用OnReceive事件,也不会从我连接的任何服务器返回任何内容.
我在这做错了什么?
参考
这些是我引用的一些链接:
> http://effbot.org/zone/socket-intro.htm
> http://www.ietf.org/rfc/rfc2326.txt
> http://folk.uio.no/meccano/reflector/smallclient.html
> http://www.samsungdforum.com/upload_files/files/guide/data/html/html_3/reference/rtsp_specification.html
我正在使用的相机是Grandstream GXV3601LL
UPDATE
我已经得出结论,问题出在RTSP服务器上,并在Grandstream的网站上的论坛上提出了一个问题.该代码可与其他服务器连接一起使用.
@R_502_323@
这对我有用,这取决于你是否处于阻止模式:
- 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.
编辑
这是一个带有RTSP服务器的真实示例(在本例中为youtube)
我使用了Indy IdTcpClient
- unit Unit11;
- interface
- uses
- Windows,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.