android - DataInputStream.readUTF is not receiving any string from Node.js Server -
today writing app (android) received strings server in node.js. socket connection fine, can send android server fine, when comes receiving server, readutf() stuck @ reading. here's android code send , receive:
socket socket = new socket("10.13.37.129",1337); dataoutputstream dataoutputstream = new dataoutputstream(socket.getoutputstream()); jsonobject jsonobject = new jsonobject(); jsonobject.put("data", "tristen"); dataoutputstream.writeutf(jsonobject.tostring()); datainputstream datainputstream = new datainputstream(socket.getinputstream()); system.out.println("receiving"); final byte[] buffer = {}; datainputstream.read(buffer); string = new string(buffer); system.out.println("received"); runnable runnable1 = new runnable() { @override public void run() { system.out.println("this string: " + string); system.out.println("this buffer: " + buffer.length); system.out.println("this buffer.tostring(): " + buffer.tostring()); textview.settext(string); } }; runonuithread(runnable1);
and server code send string:
// add 'data' event handler instance of socket clientsocket.on('data', function(data) { console.log('data: ' + data); clientsocket.write('hello\n'); clientsocket.write('world\n'); });
can see what's wrong it?
readutf()
reading strings written dataoutputstream.writeutf().
. nothing else. use read(),
bufferedreader.readline(),
etc.
Comments
Post a Comment