Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

com.dantsu.escposprinter.exceptions.EscPosConnectionException: Unable to connect to TCP device. #548

Open
namrata-jugran opened this issue Nov 16, 2024 · 0 comments

Comments

@namrata-jugran
Copy link

Hello @DantSu,

I tried to implement the TCP Printing to Network Printer however getting exception com.dantsu.escposprinter.exceptions.EscPosConnectionException: Unable to connect to TCP device.

Can you please suggest me any solutions.
Thank you.

Code

private void print() {
new Thread(new Runnable() {
public void run() {
try {
EscPosPrinter printer = new EscPosPrinter(new TcpConnection("192.168.1.5", 9100, 15), 203, 48f, 32);
printer.printFormattedText(
"[L]\n" +
"[C]ORDER N°045\n" +
"[L]\n" +
"[C]================================\n" +
"[L]\n" +
"[L]BEAUTIFUL SHIRT[R]9.99e\n" +
"[L] + Size : S\n" +
"[L]\n" +
"[L]AWESOME HAT[R]24.99e\n" +
"[L] + Size : 57/58\n" +
"[L]\n" +
"[C]--------------------------------\n" +
"[R]TOTAL PRICE :[R]34.98e\n" +
"[R]TAX :[R]4.23e\n" +
"[L]\n" +
"[C]================================\n" +
"[L]\n" +
"[L]Customer :\n" +
"[L]Raymond DUPONT\n" +
"[L]5 rue des girafes\n" +
"[L]31547 PERPETES\n" +
"[L]Tel : +33801201456\n" +
"[L]\n" +
"[C]831254784551\n" +
"[C]https://dantsu.com/"
);
} catch (Exception e) {
Log.e(TAG, "Inside IP Print Exception: " + e);
e.printStackTrace();
}
}
}).start();
}

Error

java.net.SocketTimeoutException: failed to connect to /192.168.0.118 (port 9100) from /192.168.0.114 (port 43314) after 15ms
2024-11-13 13:08:42.093 17509-17811 System.err com.myapp W at libcore.io.IoBridge.connectErrno(IoBridge.java:235)
2024-11-13 13:08:42.093 17509-17811 System.err com.myapp W at libcore.io.IoBridge.connect(IoBridge.java:179)
2024-11-13 13:08:42.093 17509-17811 System.err com.myapp W at java.net.PlainSocketImpl.socketConnect(PlainSocketImpl.java:142)
2024-11-13 13:08:42.094 17509-17811 System.err com.myapp W at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:390)
2024-11-13 13:08:42.094 17509-17811 System.err com.myapp W at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:230)
2024-11-13 13:08:42.095 17509-17811 System.err com.myapp W at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:212)
2024-11-13 13:08:42.096 17509-17811 System.err com.myapp W at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:436)
2024-11-13 13:08:42.096 17509-17811 System.err com.myapp W at java.net.Socket.connect(Socket.java:646)
2024-11-13 13:08:42.097 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.connection.tcp.TcpConnection.connect(TcpConnection.java:63)
2024-11-13 13:08:42.098 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.connection.tcp.TcpConnection.connect(TcpConnection.java:12)
2024-11-13 13:08:42.098 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.EscPosPrinterCommands.connect(EscPosPrinterCommands.java:311)
2024-11-13 13:08:42.099 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.EscPosPrinter.(EscPosPrinter.java:54)
2024-11-13 13:08:42.100 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.EscPosPrinter.(EscPosPrinter.java:27)
2024-11-13 13:08:42.101 17509-17811 System.err com.myapp W at com.myapp.Fragments.PrintFragment$3.run(PrintFragment.java:295)
2024-11-13 13:08:42.101 17509-17811 System.err com.myapp W at java.lang.Thread.run(Thread.java:1012)

2024-11-13 13:08:42.102 17509-17811 System.err com.myapp W com.dantsu.escposprinter.exceptions.EscPosConnectionException: Unable to connect to TCP device.
2024-11-13 13:08:42.102 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.connection.tcp.TcpConnection.connect(TcpConnection.java:69)
2024-11-13 13:08:42.102 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.connection.tcp.TcpConnection.connect(TcpConnection.java:12)
2024-11-13 13:08:42.103 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.EscPosPrinterCommands.connect(EscPosPrinterCommands.java:311)
2024-11-13 13:08:42.103 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.EscPosPrinter.(EscPosPrinter.java:54)
2024-11-13 13:08:42.103 17509-17811 System.err com.myapp W at com.dantsu.escposprinter.EscPosPrinter.(EscPosPrinter.java:27)
2024-11-13 13:08:42.104 17509-17811 System.err com.myapp W at com.myapp.Fragments.PrintFragment$3.run(PrintFragment.java:295)
2024-11-13 13:08:42.104 17509-17811 System.err com.myapp W at java.lang.Thread.run(Thread.java:1012)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant