1. 程式人生 > >轉--如何解決connection reset by peer(參考使用)

轉--如何解決connection reset by peer(參考使用)

rtsp 類 http 是文字協議,但是 state-full
它需要 method 或者信令來保持 state
比如 server 端的以下信令
SETUP:
Causes the server to allocate resources for a stream and start
an RTSP session.

PLAY and RECORD:
Starts data transmission on a stream allocated via SETUP.

PAUSE:
Temporarily halts a stream without freeing server resources.

TEARDOWN:
Frees resources associated with the stream. The RTSP session
ceases to exist on the server.

對於 package 的header 的分析:
ip header中會宣告:
source:202.114.99.38
destination:192.168.30.108
tcp header中會宣告:
Src Port: rtsp (554), Dst Port: 14987 (14987), Seq: 3029304, Ack: 2502, 

Len: 124
RTSP Interleaved Frame, Channel: 0x00, 8016 bytes
Real-Time Transport Protocol
rtsp使用帶外傳輸視訊資訊,使用 rtp 協議

以下是從官方網站中摘錄的 rtsp 的一些點
A presentation or a stream is identified by a textual media
identifier, using the character set and escape conventions [H3.2] of
URLs .
一個說明或者一個流是文字描述的
URLs may refer to a stream or an aggregate of   streams, i.e., a 

presentation.
而 URL 可以指向一個流或者一群流的組合
url can refer to either presentation or an individual stream within 

presentation.
url 指向一個宣告或者是一個流

以下是 協議 涉及到的3中時間表示:
SMPTE Relative Timestamps
The time code has the format   hours:minutes:seconds:frames.subframes
Normal play time (NPT) indicates the stream absolute position
relative to the beginning of the presentation.
UTC

以下是我抓包得到的資訊和分析:
-------------------------------------------------------------------
Request: OPTIONS rtsp://192.168.30.107:8554 RTSP/1.0\r\n
CSeq: 1\r\n
User-Agent: RealMedia Player (HelixDNAClient)/10.0.0.0 (win32)\r\n
ClientChallenge: a58f5ddf324d4a1ab6f864f6d3ff3fda\r\n
ClientID: WinNT_5.1_10.0.0.0_play32_RN01_EN_686\r\n
PlayerStarttime: [01/02/2010:16:36:34 -08:00]\r\n
Pragma: initiate-session\r\n
RegionData: 0\r\n
\r\n

Response: RTSP/1.0 200 OK\r\n
CSeq: 1\r\n
Date: Mon, Feb 01 2010 08:36:39 GMT\r\n
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, 

SET_PARAMETER\r\n
\r\n
------------------------------------------------------------------
//retrive description from the server and use accept to ask for 

understand
Request: DESCRIBE rtsp://192.168.30.107:8554/mp3AudioTest RTSP/1.0\r\n
CSeq: 2\r\n
User-Agent: RealMedia Player (HelixDNAClient)/10.0.0.0 (win32)\r\n
Accept: application/sdp\r\n
Bandwidth: 10485800\r\n
ClientID: WinNT_5.1_10.0.0.0_play32_RN01_EN_686\r\n
Language: zh-CN\r\n
RegionData: 0\r\n
Require: com.real.retain-entity-for-setup\r\n
SupportsMaximumASMBandwidth: 1\r\n

Response: RTSP/1.0 200 OK\r\n
Content-Base: rtsp://192.168.30.107:8554/mp3AudioTest/\r\n
Content-type: application/sdp
Content-length: 380
\r\n
Owner/Creator, Session Id (o): - 1265003496893394 1 IN IP4 

192.168.30.107
Session Name (s): Session streamed by "testOnDemandRTSPServer"
Session Information (i): mp3AudioTest
Time Description, active time (t): 0 0
Session Attribute (a): tool:LIVE555 Streaming Media v2010.01.22
Session Attribute (a): type:broadcast
Session Attribute (a): control:*
Session Attribute (a): range:npt=0-269.187(normal play time)
Session Attribute (a): x-qt-text-nam:Session streamed by 

"testOnDemandRTSPServer"
Session Attribute (a): x-qt-text-inf:mp3AudioTest
Media Description, name and address (m): audio 0 RTP/AVP 14
Connection Information (c): IN IP4 0.0.0.0
Bandwidth Information (b): AS:128
Media Attribute (a): control:track1
--------------------------------------------------------------------
Request: SETUP rtsp://192.168.30.107:8554/mp3AudioTest/track1 RTSP/1.0

\r\n
CSeq: 3\r\n
Transport: RTP/AVP;unicast;client_port=6970-

6971;mode=play,RTP/AVP/TCP;unicast;mode=play
User-Agent: RealMedia Player (HelixDNAClient)/10.0.0.0 (win32)\r\n
\r\n

Response: RTSP/1.0 200 OK\r\n
CSeq: 3\r\n
Date: Mon, Feb 01 2010 08:36:40 GMT\r\n
Transport: 

RTP/AVP;unicast;destination=192.168.30.108;source=192.168.30.107;client

_port=6970-6971;server_port=6970-6971
Session: 655A964F
\r\n

//setup 信令可能引起 455 Method Not Valid In This State
-------------------------------------------------------------------
//The PLAY method tells the server to start sending data via the
mechanism specified in SETUP ,在 describe 得到視訊檔案資訊後,用

setup 相當於協商,協商後 play
在 PLAY 中會宣告 range ,如不宣告,則是從 begining
-------------------------------------------------------------------
//GET_PARAMETER with no
entity body may be used to test client or server liveness
-------------------------------------------------------------------
//SET_PARAMETER
1、一次只能設定一個 param
2、server 可以 disallow 設定某變數
Request: SET_PARAMETER rtsp://192.168.30.107:8554/mp3AudioTest 

RTSP/1.0\r\n
CSeq: 4\r\n
frame[127:44] == 

53:75:62:73:63:72:69:62:65:3a:20:73:74:72:65:61:6d:3d:30:3b:72:75:6c:65

:3d:30:2c:73:74:72:65:61:6d:3d:30:3b:72:75:6c:65:3d:31:0d:0a
Session: 655A964F
\r\n

Request: PLAY rtsp://192.168.30.107:8554/mp3AudioTest RTSP/1.0\r\n
CSeq: 5\r\n
User-Agent: RealMedia Player (HelixDNAClient)/10.0.0.0 (win32)\r\n
Session: 655A964F
Range: npt=0-269.187000
\r\n
-------------------------------------------------------------------
//REDIRECT
S->C
-------------------------------------------------------------------
//RECORD
用 UTC 表明 start end

備註:
如果要探究 標準的 rtsp 
最好使用 vlc player
其它如暴風處理 rtsp 的方式有問題,如 mediaPlayer 它支援的不是標準的 

rtsp(處理 rtsp 的方式是微軟的一套).