java socket send & receive byte array -
In the server, I sent a byte array to the customer via Java socket
Byte [] Message = ...; DataOutputStream dout = new dataoptputstream (client.getOutputStream ()); Dout.write (message);
How can I get this byte array from the client? Anyone gives me some examples to do this code in advance
try it, it's for me doing work. Br>
Sender:
byte [] message = ... socket socket = ... data output speed dOut = new data optup stream (socket. Acoutputstream) ); DOut.writeInt (message.length); // write length of message dOut.write (message); // Message Type
Receiver:
socket socket = ... DataInputStream dIn = New DataInputStream (socket .getInputStream ()); Int length = dIn.readInt (); // Read the length of incoming message if (length> gt; 0) {byte [] message = new byte [length]; DIn.readFully (message, 0, message.length); // read message}
Comments
Post a Comment