Cant connect to camera through connect API from TCP socket when tried from a Java application.Not receiving any response from the socket.

I am developing a java application to integrate with milestone XProtect Essential+ 2020 R3 through protocol integration.I referred to imageserver SDK docs and TCP Video Viewer dot net sample code,but i could nt able to receive any response while trying to connect via connect API to image server TCP socket.I m unable to receive any response though the socket is in connected state.Please let me know if i missing something in my code.

Note : I m appending \r\n\r\n after tag too.

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 +"&amp;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+"&amp;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();
	        }
		
	}

One possible explanation is that you might use a wrong port. Per default the recording server use 7563. What server address and port to use should be read from configuration. If you use port 80 I suspect the outcome to be no response at all.

Hi Bo,

Thank you for taking time to respond,There is nothing wrong with my configuration part,I found that my code is having issue with the buffer i am using and i could able to connect to the camera.But while i am using the goto api I get ImageResponse data with binary jpg data, Can you let me know how can i transode and write them as jpg files.

Thanks.

When using no you will get what ever format the camera is set up to deliver to XProtect.

For a general guidance on the deleivered data please see the GenericByteData format - https://doc.developer.milestonesys.com/html/index.html?base=mipgenericbytedata/main.html&tree=tree_3.html

If you have jpeg data you should be able to save it to disc in a file named with the extension .jpg and it would work.

Generally the MIP SDK will help deliver the media data and does not include much in way of handling the data outside XProtect.

Hi Rie,

I am getting the data which looks like the attached txt file with **no.**It dont seems to be a jpg data.I m quite unsure of the format of the data.Can you please help me .

You receive raw data that is whatever format the camera is configured to deliver to XProtect. If you want to what is configured please explore camera settings in Management Client.

You receive raw data because you set no.

You will need to understand the delivered data, please read the GenericByteData format - https://doc.developer.milestonesys.com/html/index.html?base=mipgenericbytedata/main.html&tree=tree_3.html