java - Asyncrhonous socket client -
i'm developing asynchronous socket client based on threads. when program calls readline(), blocks indefinitely , never returns.
public class adnclient { socket socket = null; dataoutputstream dataoutputstream = null; datainputstream datainputstream = null; thread listener = new thread(new runnable() { @override public void run() { string line; try { // stop here , doesn't progress while ((line = datainputstream.readline()) != null) { //do } } catch (ioexception e) {} }); public adnclient() { try { socket = new socket("192.168.1.5", 5000); dataoutputstream = new dataoutputstream(socket.getoutputstream()); datainputstream = new datainputstream(socket.getinputstream()); listener.start(); //sender.start(); } catch (exception e) { log.e("adn", e.getmessage()); } } public void close() { listener.stop(); try { socket.close(); } catch (ioexception e) { log.e("adn", e.getmessage()); } } }
ok... i'm noob in/outputstreams... didn't send newline character, correct way recive information using
readutf() instead of
readline() thank greg kopff!
Comments
Post a Comment