Error writing to connection: Software caused connection abort: socket write error - java

F Felipe Llancachagua 3 years ago
123 1 0

Hi,
Im trying to print a image using java examples code. This is the java code:

    private void sendImageToPrint(boolean shouldStoreImage, String storePath) {
        File imageFile = new File(filePathTextField.getText());
        if (imageFile.exists() && imageFile.isFile()) {
            Connection printerConnection = null;
            try {
                printerConnection = connectionPanel.getConnection();
                printerConnection.open();
                ZebraImageI image = ZebraImageFactory.getImage(imageFile.getAbsolutePath());
                if (shouldStoreImage) {
                    ZebraPrinterFactory.getInstance(printerConnection).storeImage(storePath, image, 540, 412);
                }
                ZebraPrinterFactory.getInstance(printerConnection).printImage(image, 0, 0, 550, 412, false);
            } catch (ConnectionException e) {
                DemoDialog.showErrorDialog(ImagePrintDemo.this, e.getMessage(), "Connection Error!");
            } catch (ZebraPrinterLanguageUnknownException e) {
                DemoDialog.showErrorDialog(ImagePrintDemo.this, e.getMessage(), "Connection Error!");
            } catch (IOException e) {
                DemoDialog.showErrorDialog(ImagePrintDemo.this, e.getMessage(), "Image Error!");
            } catch (ZebraIllegalArgumentException e) {
                DemoDialog.showErrorDialog(ImagePrintDemo.this, e.getMessage(), "Illegal Arguments!");
            } finally {
                try {
                    if (printerConnection != null) {
                        printerConnection.close();
                    }
                } catch (ConnectionException e) {
                }
            }
        } else {
            DemoDialog.showErrorDialog(ImagePrintDemo.this, "\"" + imageFile.getAbsolutePath() + "\"" + " is not a valid path.", "Invalid File Path!");
        }
    }

the error occur when is executed the following code:
  ZebraPrinterFactory.getInstance(printerConnection).printImage(image, 0, 0, 550, 412, false);

and show this error:
Error writing to connection: Software caused connection abort: socket write error

Im using an emulator printer zpl and it works when i send commands fron notepad for instance.

I really appreciate your help.

Felipe.

Please register or login to post a reply

1 Replies

D Dmitry Prokhorov

Hello Felipe,

You may need to install most recent version of Link-OS Multiplatform SDK​ .

In case you are using Java on a PC, please see this source code as an example:
TcpConnection (Zebra API (build v2.14.5097))
And documentation is here: Link-OS SDK - Zebra Technologies Techdocs

In case you are using Java on Android, please see this source code as an example:
TcpConnection (Zebra API for Android (build v2.14.5097))
And documentation is here: Link-OS SDK - Zebra Technologies Techdocs

Dmitry Prokhorov
Software Engineer, Kutir Mobility
Posted on behalf of Zebra Technologies

CONTACT
Can’t find what you’re looking for?