Problemas com um laço

olá!

estou tentando a dias criar um programinha q um cliente envie um array d bytes para um servidor, esse serv receba esse array e com isso, consiga encher um buffer de espaço do tamanho do array. Estou tendo dificuldades em encher esse buffer, pois nao consigo realizar o laço para o enchimento e tb não consigo alocar dinamicamente o tamanho do buffer. alguem podia m ajudar/

segue abaixo os codigos!
:wink:

CLIENTE

public class ClientBuffer
{

public static void main(String args[])
{
     Socket cliente = null;
         
    try
    {
        cliente = new Socket("127.0.0.1",7000);
        DataOutputStream output = new DataOutputStream(cliente.getOutputStream());
        byte[] DataBytes = "Testando o programa".getBytes();
        output.writeInt(DataBytes.length);
        output.write(DataBytes);
    }
  
        catch(IOException ioex)
        {
            ioex.printStackTrace();
        }   

        finally
        {
            try
            {
                cliente.close();
            }
        
                catch(IOException e){}
        }
}

}

SERVIDOR

public class ServerBuffer
{
private ByteBuffer buffer;

private void createBuffers() 
{
    buffer.allocate(19); -----NAO CONSIGO ALOCAR DINAMICAMENTE
}

public static void main(String args[])
{
    ServerSocket server = null;
Socket cliente = null;
    
    try
{
        server = new ServerSocket(7000);
        System.out.println("Aguardando um cliente conectar...");
    cliente = server.accept();
        System.out.println("Conexão efetuada");
        System.out.println("");
        
        DataInputStream entrada = new DataInputStream(cliente.getInputStream());
    int size = entrada.readInt();
        System.out.println(size);
        byte[] recvBytes = new byte[size];
    entrada.read(recvBytes);
        
        
        for( int i = 0; i <= size; i++ ) ----NAO CONSIGO FAZER UM LAÇO PRA ENCHER O BUFFER 
        {
            buffer.put(recvBytes[i]);
        }
        
    }
    catch(IOException e)
    {
    	System.out.println("Algum problema ocorreu ao criar ou enviar dados pelo socket.");
    }
        finally
        {
            try
	{
                cliente.close();
	}
                catch(IOException e){}
        }

}
}

[saco cheio]Não vou ler o post se indentação. Use a tag code.[/saco cheio]