java - read bits and not int from a socket -


Manufacturers are:

  public TcpConnection (string address, integer port) {this.adress = adress; This.port = port; Try {socket = new socket (address, port); System.out.println ("Open Connection"); Out = new print-वाइटर (socket.getOutputStream (), true); InputStream r = New DataInputStream (socket.getInputStream ()); In = new BufferedReader (new InputStreamReader (socket.getInputStream ())); } Hold (unknownhostexception e) {// TODO: exception to exception}} (IOException e) {e.printStackTrace (); }}  

Then I read my socket in a while with in.read () .

This allows me to read the socket int int, but I need a finer granularity. (Some information in the answer is encoded in 2 bytes, in some bits, in some 64 bytes ....) then I need to read 2 bytes, then a little bit. So another bit, then 1 byte and every bit of this byte are inspected.

Earlier I was thinking: "OK, I want to meet in a string binary presentation", (To via integer) ToBinaryString (whatIget) ) but it's just stupid And the error is prone.

I am sure that I am missing something to overcome this sudden problem. some ideas?

Edit2: When I read an int, I read 32 bits (4 bytes) "I am deleting it because it is wrong and is not an issue of question. Thus, Reader.read () reads an int, if this method is read only one byte, is she reading 1/4 inch ??!?

reads 8 bit / 1 byte at a time.

You can get a byte, word, intestine, long, UTF-8 string etc. from the data inputstream if you have more information on the type of DataInputStream type. Ho

  DataInputStream r = New DataInputStream (socket.getInputStream ()); R.readLong (); R.readShort (); Instead of  

  InputStream r = New DataInputStream (socket.getInputStream ());  

However, for words, int and long term 'expired' cases cases. DataInputStream combines the bytes in the built-in Aadian format, where you can have your data in the format of a little data. After reading from the DIS you may need to swap the bytes. This is where and his friends come in work.

If you need some size data retrieval (for example read 6 bits, then 4, then 12, etc.), then you can check the answers. / P>

Edit: removed 8 bits because it is misleading in this context.

Edit 2: Re-enter my third sentence.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -