应用程序,我在其中放置有关服务器,端口,用户名和密码的信息(我可以使用服务器软件添加帐户).该应用程序从相机流式传输视频我也可以通过http(只有IE)与dvr连接,然后显示activeX应用程序.
我要做的是编写类似的应用程序,但我遇到了一个问题 – 如何从dvr获取视频流?我不是Java专家,尝试连接dvr,但没有成功.
这是我的代码:
import java.net.*;
import java.io.*;
public class VideoStream
{
final static int BUFFER_SIZE = 1024000;
public static void main(String[] args) throws Exception
{
Authenticator.setDefault(new Authenticator()
{
protected PasswordAuthentication getPasswordAuthentication()
{
System.out.println("Authenticatting...");
PasswordAuthentication p=new PasswordAuthentication("login", "password".toCharArray());
return p;
}
});
Socket s = new Socket();
String host = "192.168.80.107"; //192.168.80.107
PrintWriter s_out = null;
BufferedReader s_in = null;
BufferedInputStream bufferedInputStream = null;
try
{
s.connect(new InetSocketAddress(host, 34599));
System.out.println("Is connected? : " + s.isConnected());
s_out = new PrintWriter(s.getOutputStream(), true);
s_in = new BufferedReader(new InputStreamReader(s.getInputStream()));
//bufferedInputStream = new BufferedInputStream(s.getInputStream());
}
catch(UnknownHostException e)
{
e.printStackTrace();
System.exit(1);
}
catch(Exception e)
{
e.printStackTrace();
System.exit(1);
}
byte[] b = new byte[BUFFER_SIZE];
//bufferedInputStream.read(b);
int bytesRead = 0;
System.out.println("Reading... /n");
while((bytesRead = s_in.read()) > 0)
{
System.out.println(s_in.readLine());
}
System.out.println("Done");
}
我尝试了不同的端口(TCP和包含Android应用程序).套接字与服务器连接,但当我尝试使用read()方法(甚至是while循环)时它会“挂起”.身份验证器也不起作用.
有关dvr的一些信息:
>协议支持:TCP / IP,UDP,SMTP,NTP,DHCP,DDNS
>视频压缩:H.264
>操作系统:linux
我会非常感谢任何建议.