2012-09-04 109 views
1

我正在使用Aforge嘗試從IP攝像機獲取實時流。我的問題是,由於某種原因,我的連接不斷關閉。出於測試目的,我將相機直接連接到我的電腦,並通過此LAN連接到相機。Aforge從IP攝像頭直播流HttpWebRequest

錯誤:

The underlying connection was closed: The connection was closed unexpectedly.

這裏是我使用的代碼:

stream.NewFrame += new NewFrameEventHandler(video_NewFrame); 
stream.VideoSourceError += new VideoSourceErrorEventHandler(stream_VideoSourceError); 
stream.Login = "login"; 
stream.Password = "pass"; 
stream.RequestTimeout = 10000; 
stream.Source = "http://192.168.0.33/nphMotionJpeg?Resolution=320x240&Quality=Standard"; 
stream.Start(); 

我有哪裏有人建議把設置在鋸的app.config,我已經做了以及:

<system.net> 
    <settings> 
    <httpWebRequest useUnsafeHeaderParsing="true"/> 
    </settings> 
</system.net> 

沒有編輯關閉app.config,我得到一個不同的錯誤。 (違反協議)

有沒有人遇到過這些問題或知道如何讓它工作?

注意:我也嘗試獲取數據沒有Aforge like this但它導致了同樣的錯誤。

+0

嘗試在VLC中打開它,看看它是否在那裏工作。當我不確定我的代碼是否正常工作時,我發現VLC非常適合測試MJPEG連接。 – Peter

+0

可能與http://stackoverflow.com/questions/10823848/mjpegstream-display-stream-aforge-video-dll(雖然沒有足夠的細節在其他問題上肯定知道) – Peter

+0

@Peter是的,看起來有關。沒有信息雖然 – CSharpDev

回答

1

我不認爲這是aforge的一個選項(https://code.google.com/p/aforge/source/browse/trunk/Sources/Video/MJPEGStream.cs),但它看起來像相機預計HTTP v1.0。請參閱手冊,http://csj.psn-web.net/netwkcam_net/download/us/document/NEW_Camera_CGI_Interface_v4.30.pdf,第56頁。

(1) Start reception Establish a connection (open the socket), and send the following command string to HTTP port. "GET http:// xxx.xxx.xxx.xxx:yy/nphMotionJpeg?Resolution=320x240&Quality=Standard HTTP/1.0\r\n" xxx.xxx.xxx.xxx: IP address or domain name yy: HTTP port no. (Not required if the port number is set to 80)

。如果你有訪問代碼,你可以嘗試

//setting http v1.0 in c# 
HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(address); 
request.ProtocolVersion = HttpVersion.Version10; 

另外,儘量讓客人訪問,並從代碼中刪除您的用戶名/密碼並看看是否有效。

+0

試過這個,仍然是同樣的問題。好消息,但。 – CSharpDev

2

請嘗試以下操作以查看它是否有效。

stream.Login = "login"; 
stream.Password = "pass"; 
stream.ForceBasicAuthentication = true; 
stream.RequestTimeout = 10000; 
stream.Source = "http://192.168.0.33/nphMotionJpeg?Resolution=320x240&Quality=Standard"; 
stream.Start();