I am connected to Wifi from my mobile device and I need to connect to Bixolon printer which connected to same network but has private IP address?

Keywords: java android

Question: 

I am trying to make an application for Android which is connected to wi-fi on the network and there is this printer which is connected to same router but having private IP, how to connect and send the print command ? Printer type is Bixolon.

Printer info- IP address : 10.1.10.218 Gateway: 10.1.10.1 Port: 9100 Subnet: 255.255.255.0

  1. I tried using Socket and sending the data using OutputStream. Below is the sample code,
  2. I tried to use SDK which is provided by Bixolon, but sadly it does not work for me as well. Below is the code sample,

-> Code for the first try using Socket,

            DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
            byte[] buffer; //= new byte[BUFFER_SIZE];
            String data =
                    "Hello this is the data which is coming from Android application.";
            buffer = data.getBytes();

            //while (data.read(buffer) !=-1){
            outToServer.write(buffer);
            //}
            outToServer.flush();

-> Code for the second try using SDK-

        String logicalName = "SRP-330II";

        // Open the old configuration file or open the new one
        try {
            bxlConfigLoader.openFile();
        }
        catch (Exception e) {
            bxlConfigLoader.newFile();
        }

        // Set the configuration
        bxlConfigLoader.addEntry(logicalName,
                BXLConfigLoader.DEVICE_CATEGORY_POS_PRINTER,
                BXLConfigLoader.PRODUCT_NAME_SRP_330II,
                BXLConfigLoader.DEVICE_BUS_ETHERNET, str_printerIp);

        // Save the configuration file
        try {

            for (Object entry : bxlConfigLoader.getEntries())
            {
                JposEntry jposEntry = (JposEntry)entry;
                String strLogicalname = jposEntry.getLogicalName();
                bxlConfigLoader.removeEntry(strLogicalname);
            }
            bxlConfigLoader.saveFile();
        }
        catch (Exception e) {
            e.printStackTrace();
            Log.wtf(TAG, "Error while saving configuration file");
        }

        // Open up the printer
        POSPrinter posPrinter = new POSPrinter(this);
        try {
            posPrinter.open(logicalName);
            posPrinter.claim(5000);
            posPrinter.setDeviceEnabled(true);
            posPrinter.setAsyncMode(true);
            posPrinter.setCharacterEncoding(BXLConst.CE_ASCII);
            posPrinter.printNormal(POSPrinterConst.PTR_S_RECEIPT, "Print the data\n\n");
        }
        catch (Exception e) {
            Log.wtf(TAG, "POS printer error");
            e.printStackTrace();
        }

Getting exception "Permission Denied".

Answers: