Hi!
Try to use decimal header, like, 123456000000000000000.
Try to use decimal header, like, 123456000000000000000.
import java.io.*;
import java.net.*;
public class HsmClient {
private static Socket socket = null;
private static int header = 0;
private static String HSM_IP;
private static long HSM_PORT;
private static int HEADER_LENGTH = 4;
private static void connect () throws IOException {
socket = new Socket(HSM_IP, HSM_PORT);
}
private static void disconnect () throws IOException {
socket.close();
}
private static String setHeader () {
header++;
String headerStr = Integer.toString(header);
while (headerStr.length() != HEADER_LENGTH) {
headerString = ‘0’ + headerString;
}
return rs;
}
private static String sendCommand (String command) throws IOException {
String response = null;
command = setHeader() + command;
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream()));
DataInputStream in = new DataInputStream(new BufferedInputStream(socket.getInputStream()));
out.writeUTF(command);
out.flush();
response = in.readUTF();
return response;
}
private static String sendEcho () throws IOException {
String to_hsm = "NC";
return sendCommand(to_hsm);
}
public static void main (String[] args) {
for (int i = 0; i < args.length; i++) {
if (args[i].equals(„-i”)) {
HSM_IP = args[i + 1];
}
else if (args[i].equals(„-p”)) {
HSM_PORT = args[i + 1];
}
try {
connect();
sendEcho();
System.out.println(sendEcho());
disconnect();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
}