java - Read and Write strings via ByteBuf using byte[] array -


i'm trying send string through netty bytebuf. first of convert string byte array that:

bytebuf.writeint(this.servername.length()); bytebuf.writeint(this.ipadress.length());  bytebuf.writebytes(this.servername.getbytes(standardcharsets.utf_8)); bytebuf.writebytes(this.ipadress.getbytes(standardcharsets.utf_8)); 

this works well, don't know how read bytes convert them string?

i tried that:

int snlen = bytebuf.readint(); int iplen = bytebuf.readint();  byte[] bytes = new byte[bytebuf.readablebytes()];  system.out.println(bytebuf.readbytes(bytes).readbyte()); this.ipadress = ""; 

there must bytes back. can send bytes string can't bytes @ end? seems there method that, don't have idea how that.

i hope can me. in advance! :)

in netty 4.1 can use:

bytebuf.writecharsequence(...) bytebuf.readcharsequence(...) 

Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -