Please provide guidelines to pull Image and recorded video for specific time/time interval through Java application.
We do not provide specific guidelines for Java, but please have a look at the TCP Video Viewer protocol sample, which shows how to use our protocols for fetching video. And generally refer to the ImageServer protocol documentation in the SDK:
Hi @sudha mani ,
I was trying to build similar java application to pull a recorded video within specific time interval using TCP socket as specified in the TCP video viewer example above.But i am not able to get any of response from connect API from the socket.I assume i m missing something in my code.Can you please help me if you already could able to achieve this?
The following is my code snippet :
public static void connectCamera(String tk) throws ParserConfigurationException,
SAXException, IOException, UnknownHostException {
//Provide Input SOAP Message
String bodyAsString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+ "<methodcall>"
+ "<requestid>0</requestid>"
+ "<methodname>connect</methodname>"
+ "<username>"+ userName +"</username>"
+ "<password>"+ password +"</password>"
+ "<cameraid>"+ deviceId +"</cameraid>"
+ "<alwaysstdjpeg>no</alwaysstdjpeg> "
+ "<connectparam>id="+ deviceId +"&connectiontoken="+ tk +"</connectparam>"
+ "</methodcall>\r\n\r\n";
// String bodyAsString =
// "<?xml version=\"1.0\" encoding=\"utf-8\"?><methodcall><requestid>0</requestid>" +
// "<methodname>connect</methodname><username>a</username><password>a</password>" +
// "<cameraid>"+ deviceId +"</cameraid><alwaysstdjpeg>yes</alwaysstdjpeg>" +
// "<transcode><allframes>yes</allframes></transcode>" + // Add this line to get all frames in a GOP transcoded
// "<connectparam>id="+deviceId+"&connectiontoken="+tk +
// "</connectparam></methodcall>\r\n\r\n";
System.out.println("Request XML for Camera Connect :::::");
System.out.println(bodyAsString);
try {
// establish the socket connection to the server
// using the local IP address, if server is running on some other IP, use that
Socket socket = new Socket(host, tcpPort);
System.out.println("Socket Connected");
// write to socket using OutputStream
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
// Initializing request content
byte[] request = bodyAsString.getBytes(StandardCharsets.UTF_8);
// DataOutputStream.writeInt() writes in big endian and
// DataInputStream.readInt() reads in big endian.
// using a ByteBuffer to handle little endian instead.
byte[] header = new byte[5];
ByteBuffer buf = ByteBuffer.wrap(header, 1, 4);
buf.order(ByteOrder.LITTLE_ENDIAN);
// Initializing request header
header[0] = (byte) 0xF0;
buf.putInt(request.length);
System.out.println("Sending request to Socket Server");
// Sending request
dos.write(header);
dos.write(request);
dos.flush();
//socket.shutdownOutput();
System.out.println("Request was sent. Awaiting response.");
// read from socket using InputStream
DataInputStream dis = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
// Read response header
//dis.readFully(header);
dis.read(header, 0, header.length - 1);
buf.flip();
// Read response content
byte[] response = new byte[buf.getInt()];
//dis.readFully(response);
dis.read(response, 0, response.length - 1);
System.out.println("byte[]:::" + response);
// convert the content into a string
String message = new String(response, StandardCharsets.UTF_8);
System.out.println("Message: " + message);
// close your resources
dis.close();
dos.close();
socket.close();
Thread.sleep(100);
} catch (Exception ex) {
ex.printStackTrace();
}
}
Thanks in advance.