Hi all
I have socket based client server application. And my question is how to read a byte array at client side. Here I'm sending byte array from server and using BufferedReader at client side how to write incoming data to a byte array?
Server code
public static void main(String args[])
{
ServerSocket sock = null; // original server socket
Socket clientSocket = null; // socket created by accept
PrintWriter pw = null; // socket output stream
BufferedReader br = null;
try
{
sock = new ServerSocket(serverPort);
clientSocket = sock.accept();
pw = new PrintWriter(clientSocket.getOutputStream(), true);
pw.println(getImageasByteArray()); // write byte array to socket
// rest oh the code
}
}
public static byte[] getImageasByteArray()
{
// implementation
}
client code
public static void main(String args[])
{
Socket sock = null;
BufferedReader br = null;
try
{
sock = new Socket(serverIPname, serverPort);
br = new BufferedReader(new InputStreamReader(sock.getInputStream()));
String answer = br.readLine(); // here how to read the content to byte array
}
}
So instead of reading the content to string(above case) I need to write whole content to byte array. So I have to create a byte array with the size known. So to do this I need to know the size of the incoming byte array size isn't it?
So can some one please help me.
It's great if u can direct me to implemented example.
Any help highly appreciated
Thank You