Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7494791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:46:48+00:00 2026-05-29T17:46:48+00:00

I’m trying to connect a fingerprint device (tc400) C2 device on Linux. The hardware

  • 0

I’m trying to connect a fingerprint device (tc400) C2 device on Linux. The hardware vendor provide me with a DLL file which I can’t use on Linux so I tried to use socket programming and communicate with the device using hex code. The problem is the device is not responding at all and the code crashes when I try to get the input stream of the client socket.
This is all of my code:

 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();
}
 }

If anyone could help me to communicate with the device I will be grateful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T17:46:50+00:00Added an answer on May 29, 2026 at 5:46 pm

    Storing binary data in Strings is IMHO a bad idea. Especially because the used getBytes() method of String returns bytes depending of the system default charset (un Linux mostly UTF-8) which may produce unexpected bytes sequences.

    You should better use byte[] instead of String. Byte arrays can also be defined this way:

    new byte{(byte) 0xA5, (byte) 0x00, (byte) 0x00 (byte) 0x00 (byte) 0x00 (byte) 0x30 (byte) 0x00 (byte) 0x00 (byte) 0x51 (byte) 0x10}
    

    Alternatively you can use Apache common Codec Hex class for converting hexadecimal strings to byte array.

    The second mistake is the usage of ObjectInputStream and readObject() for reading the redurned data. It is designed for reading Java serialized class data. Use better use DataInputStream and this code:

    byte msg [] = new byte[1024];
    System.out.println("D6");
    int bytesReturned = in.read(msg, 0, msg.length);
    

    Note that the result may be incomplete in case the data is not transfered as one block. If you know the exact response msg size use readFull(msg) instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to render a haml file in a javascript response like so:
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.