我试图在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