I am trying to send an image file from one PC (the client) to another PC where MATLAB is running (the server) and the output image comes out empty.
From a different discussion, I understood that the main problem is some "Image Matrix mismatch" between Java and MATLAB. However, I do not fully understand the problem.
I would be grateful if you could give me some suggestions.
Client Java code:
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import javax.imageio.ImageIO;
public class myclientimage
{
public static void main(String args[]) throws IOException
{
BufferedImage img = ImageIO.read(new File("D:\\zzz.jpg"));
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(img, "jpg", baos);
baos.flush();
byte[] buffer = baos.toByteArray();
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("192.168.0.102");
System.out.println(buffer.length);
DatagramPacket packet = new DatagramPacket(buffer, buffer.length, IPAddress, 9091);
clientSocket.send(packet);
System.out.println("aaaa");
}
}
Server MATLAB code:
udpA=udp('192.168.0.104', 9090,'LocalPort', 9091);
fopen(udpA);
A = fread(udpA, 200000);
du = reshape(A,size(A)); % converting vector du to 3d Image array
imwrite(uint8(du), 'du.jpg'); %save our du to file du.jpg
I = imread('du.jpg'); %test if it saved correctly
imshow(I);
fclose(udpA);