2012-09-04 108 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();