sockets - Java: Difference with dis.read() and dis.readUTF() in DataInputStream -
simple question.
what difference dis.read() , dis.readutf()?
for example, dis.read() read byte array, , dis.readutf() access string type.
is correct?
if server has implements dis.readutf(), can not read byte stream?
@override public void run() { // todo auto-generated method stub while(menabled) { if (!mfilereceive) { try { // read string tmpstr = dis.readutf(); // here come `dis.readutf()` <- can not read byte array? mstringbuffer += tmpstr; if (tmpstr.length() >= 4096) continue; system.out.println("print : " + mstringbuffer); parse = new parsejson(null, mstringbuffer.tostring()); // ack message if (mackenabled) { mfilename = "{opcode:0x06,ack:c" + parse.getparseddata().get("ack").substring(1) + "}"; dos.writeutf(mfilename); dos.flush(); system.out.println("ack message send : " + mfilename); mfilename = null; } if (parse.getparseddata().get("opcode").equals("155")) { mfilereceive = true; } parse.clear(); parse = null; } catch (ioexception e) { // todo auto-generated catch block system.out.println("serverthread disconnect"); break; }
readutf() reads stream in representation of unicode character string encoded in modified utf-8 format; string of characters returned string.
you should use read method takes bytes array argument. here explanation:
public final int read(byte[] b) throws ioexception
reads number of bytes contained input stream , stores them buffer array b. number of bytes read returned integer.
Comments
Post a Comment