我試圖在Linux上連接指紋設備(tc400)C2設備。硬件供應商提供了一個我不能在Linux上使用的DLL文件,因此我嘗試使用套接字編程並使用十六進制代碼與設備進行通信。問題是設備根本沒有響應,當我嘗試獲取客戶端套接字的輸入流時,代碼崩潰。 這是我的所有代碼:使用Java和Hex連接C2設備
import java.io.*;
import java.net.*;
public class Client{
Socket requestSocket;
ObjectOutputStream out;
ObjectInputStream in;
String message;
Client(){}
void run()
{
try{
//1. creating a socket to connect to the server
requestSocket = new Socket("172.16.16.192", 5010);
//requestSocket = new Socket("localhost", 5010);
System.out.println("Connected to Machine in port 5010");
//2. get Input and Output streams
System.out.println("-1");
out = new ObjectOutputStream(requestSocket.getOutputStream());
//out.flush();
System.out.println("D0");
sendMessage("A5\\x00\\x00\\x00\\x00\\x30\\x00\\x00\\x51\\x10"); // getting the device information
in = new ObjectInputStream(requestSocket.getInputStream());
//3: Communicating with the server
System.out.println("D1");
do{
System.out.println("D2");
try{
System.out.println("D3");
sendMessage("A5\\x00\\x00\\x00\\x00\\x30\\x00\\x00\\x51\\x10"); // getting the device information
System.out.println("D5");
byte msg [] = null;
System.out.println("D6");
msg = (byte[])in.readObject();
System.out.println("D7");
System.out.println("Machine>" + msg);
//sendMessage(message);
//message = (String)in.readObject();
}
catch(ClassNotFoundException classNot){
System.err.println("data received in unknown format");
}
}while(!message.equals("bye"));
}
catch(UnknownHostException unknownHost){
System.err.println("You are trying to connect to an unknown host!");
}
catch(IOException ioException){
ioException.printStackTrace();
}
finally{
//4: Closing connection
try{
in.close();
out.close();
requestSocket.close();
}
catch(IOException ioException){
ioException.printStackTrace();
}
}
}
void sendMessage(String msg)
{
System.out.println("D4");
try{
System.out.println("D41");
out.writeObject(msg.getBytes());
out.flush();
System.out.println("client>" + msg);
}
catch(IOException ioException){
ioException.printStackTrace();
}
}
public static void main(String args[])
{
Client client = new Client();
client.run();
}
}
如果有人能幫助我與設備我會感激通信。
我可以問問你是怎麼做到的?我有C3設備,我只能在Windows上與它進行通信,非常適合使用linux替代品。 – Jeremy 2012-03-20 10:40:33