Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

how to send a byte array in socket java

byte[] message = ...
Socket socket = ...
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());

dOut.writeInt(message.length); // write length of the message
dOut.write(message);           // write the message
Comment

how to send a byte array in socket java

Socket socket = ...
DataInputStream dIn = new DataInputStream(socket.getInputStream());

int length = dIn.readInt();                    // read length of incoming message
if(length>0) {
    byte[] message = new byte[length];
    dIn.readFully(message, 0, message.length); // read the message
}
Comment

PREVIOUS NEXT
Code Example
Java :: how to overwrite a text file in java 
Java :: nested for each loop java 
Java :: Do not concatenate text displayed with setText. Use resource string with placeholders. 
Java :: start new activity android 
Java :: java text file to arraylist 
Java :: change image on button click android studio 
Java :: remove all new line and other in string using java 
Java :: java set from string array 
Java :: java for 
Java :: java triangle 
Java :: java distinct by key 
Java :: decode base64 to file java 
Java :: multiple type array java 
Java :: conversion of string to integer in java 
Java :: counting repeated characters in a string in java 
Java :: while loop java 
Java :: 8.1.1. Declaring an Array¶ 
Java :: cls java 
Java :: spannable string in android java for color 
Java :: java how to convert string to int 
Java :: rotate a linked list 
Java :: switch case java with char 
Java :: long vs int java 
Java :: java call method from another class example 
Java :: load a list from text file java 
Java :: volley library 
Java :: java declare a list 
Java :: convert double into integer 
Java :: how to take max value from priority queue in java 
Java :: arraylist replace value java 
ADD CONTENT
Topic
Content
Source link
Name
4+1 =