android - Java Socket throws IOException Sometimes -
i making android application needs print receipts on network printer. printer using "thermal receipt printer tysso prp 300".
my problem prints , after printing 2 or 3 times stops printing , start receiving ioexception. tried restarting mobile/application/force-stop/printer/pinged-printer nothing.
using asynctask
communication.
below socket code:
private class myprinter extends asynctask<string, string, string> { socket sock; printwriter ostream; datainputstream dis; public myprinter() { } protected string doinbackground(string... params) { try { sock = new socket(params[0], integer.parseint(params[1])); sock.setsotimeout(300); if(sock.getremotesocketaddress() != null) { ostream = new printwriter(sock.getoutputstream()); ostream.println(params[2]); } ostream.flush(); ostream.close(); sock.shutdownoutput(); sock.close(); } catch (unknownhostexception e) { log.i("cycle", "00"); e.printstacktrace(); } catch (ioexception e) { log.i("cycle", "11"); e.printstacktrace(); } finally{ } return null; } @override protected void onpostexecute(string result) { super.onpostexecute(result); if(pdialog != null) if(pdialog.isshowing()) pdialog.dismiss(); currentorder.dismiss(); } }
stack trace:
04-06 18:58:55.009: w/system.err(5262): java.net.socketexception: failed connect /192.168.1.150 (port 9100) after 90000ms: isconnected failed: ehostunreach (no route host) 04-06 18:58:55.018: w/system.err(5262): @ libcore.io.iobridge.isconnected(iobridge.java:256) 04-06 18:58:55.018: w/system.err(5262): @ libcore.io.iobridge.connecterrno(iobridge.java:178) 04-06 18:58:55.019: w/system.err(5262): @ libcore.io.iobridge.connect(iobridge.java:112) 04-06 18:58:55.020: w/system.err(5262): @ java.net.plainsocketimpl.connect(plainsocketimpl.java:192) 04-06 18:58:55.021: w/system.err(5262): @ java.net.plainsocketimpl.connect(plainsocketimpl.java:172) 04-06 18:58:55.021: w/system.err(5262): @ java.net.socket.startupsocket(socket.java:575) 04-06 18:58:55.022: w/system.err(5262): @ java.net.socket.tryalladdresses(socket.java:130) 04-06 18:58:55.023: w/system.err(5262): @ java.net.socket.<init>(socket.java:180) 04-06 18:58:55.023: w/system.err(5262): @ java.net.socket.<init>(socket.java:152) 04-06 18:58:55.024: w/system.err(5262): @ com.example.pointofsale.fragments.homescreen_current_orders$myprinter.doinbackground(homescreen_current_orders.java:319) 04-06 18:58:55.024: w/system.err(5262): @ com.example.pointofsale.fragments.homescreen_current_orders$myprinter.doinbackground(homescreen_current_orders.java:1) 04-06 18:58:55.025: w/system.err(5262): @ android.os.asynctask$2.call(asynctask.java:287) 04-06 18:58:55.026: w/system.err(5262): @ java.util.concurrent.futuretask$sync.innerrun(futuretask.java:305) 04-06 18:58:55.028: w/system.err(5262): @ java.util.concurrent.futuretask.run(futuretask.java:137) 04-06 18:58:55.028: w/system.err(5262): @ android.os.asynctask$serialexecutor$1.run(asynctask.java:230) 04-06 18:58:55.029: w/system.err(5262): @ java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor.java:1076) 04-06 18:58:55.033: i/surfacetextureclient(5262): [0x52739378] frames:53, duration:1.001000, fps:52.933781 04-06 18:58:55.034: w/system.err(5262): @ java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor.java:569) 04-06 18:58:55.035: w/system.err(5262): @ java.lang.thread.run(thread.java:856) 04-06 18:58:55.036: w/system.err(5262): caused by: libcore.io.errnoexception: isconnected failed: ehostunreach (no route host) 04-06 18:58:55.038: w/system.err(5262): @ libcore.io.iobridge.isconnected(iobridge.java:234)
Comments
Post a Comment