Investigamos por todo el mundo on line y así brindarte la solución para tu problema, si continúas con dificultades déjanos la pregunta y te respondemos con mucho gusto.
Ejemplo: java envía una imagen a través de un socket
publicclassSendpublicstaticvoidmain(String[] args)throwsExceptionSocket socket =newSocket("localhost",13085);OutputStream outputStream = socket.getOutputStream();BufferedImage image =ImageIO.read(newFile("C:\Users\Jakub\Pictures\test.jpg"));ByteArrayOutputStream byteArrayOutputStream =newByteArrayOutputStream();ImageIO.write(image,"jpg", byteArrayOutputStream);byte[] size =ByteBuffer.allocate(4).putInt(byteArrayOutputStream.size()).array();
outputStream.write(size);
outputStream.write(byteArrayOutputStream.toByteArray());
outputStream.flush();System.out.println("Flushed: "+System.currentTimeMillis());Thread.sleep(120000);System.out.println("Closing: "+System.currentTimeMillis());
socket.close();publicclassReceivepublicstaticvoidmain(String[] args)throwsExceptionServerSocket serverSocket =newServerSocket(13085);Socket socket = serverSocket.accept();InputStream inputStream = socket.getInputStream();System.out.println("Reading: "+System.currentTimeMillis());byte[] sizeAr =newbyte[4];
inputStream.read(sizeAr);int size =ByteBuffer.wrap(sizeAr).asIntBuffer().get();byte[] imageAr =newbyte[size];
inputStream.read(imageAr);BufferedImage image =ImageIO.read(newByteArrayInputStream(imageAr));System.out.println("Received "+ image.getHeight()+"x"+ image.getWidth()+": "+System.currentTimeMillis());ImageIO.write(image,"jpg",newFile("C:\Users\Jakub\Pictures\test2.jpg"));
serverSocket.close();
Comentarios y calificaciones del tutorial
Puedes añadir valor a nuestra información contribuyendo tu experiencia en las interpretaciones.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)