Imagens grandes via socket

podem me fazer um favor ?? podem me ajudar a enviar imagens grandes via socket ?? eu consigo enviar apenas imagens de 64kb é preciso enviar imagens de 1mb para cima.

obbriado pela atenção.
Cliente
Socket s = new Socket(“localhost”, 2500);

	FileInputStream f = new FileInputStream("C:\\Users\\Jonatas\\Pictures\\1.jpg");

	byte[] b = new byte[100000000];
	int tamanhoArquivo = f.read(b);

	OutputStream saida = s.getOutputStream();

	saida.write(b, 0, tamanhoArquivo);

	saida.close();

	saida.flush();
	f.close();
}

Servidor

try {

		ServerSocket s = new ServerSocket(2500);
		Socket socket = s.accept();
		InputStream in = socket.getInputStream();
		byte[] b = new byte[100000000];
		int i = in.read(b);

		FileOutputStream f = new FileOutputStream("saida.jpg");

		f.write(b, 0, i);
	} catch (IOException e) {

		e.printStackTrace();
	}

O cliente e o servidor tem o mesmo código?

1 curtida

corrigido!

Código pra copiar conteúdo de um InputStream para um OutputStream:

public static void copy(InputStream from, OutputStream to) throws IOException {
    final int count = 8192; // 8KB
    byte[] bytes = new byte[count];
    for (int read = -1; (read = from.read(bytes, 0, count)) != -1; to.write(bytes, 0, read)) {}
    to.flush();
}

Cliente:

    Socket s = new Socket(“localhost”, 2500);
    FileInputStream entrada = new FileInputStream("C:\\Users\\Jonatas\\Pictures\\1.jpg");
    OutputStream saida = s.getOutputStream();
    copy(entrada, saída);
    saida.close();
    entrada.close();

Servidor:

    ServerSocket s = new ServerSocket(2500);
    Socket socket = s.accept();
    InputStream in = socket.getInputStream();
    FileOutputStream out = new FileOutputStream("saida.jpg");
    copy(in, out);
    out.close();
    in.close();
1 curtida

perfeito,cara vc é um gênio.agora so preciso entender cada linha dessa é tentar desenvolver um metodo parecido k, obrigado!!