I am lately trying to create a program, just like teamviewer. It's going kinda well, but I am currently facing a problem.

I am trying to make my program send an image over the socket. When I run this code, it never outputs "Image should be sent!", so I think the problem is in the ImageIO.write line.

```
BufferedImage screencapture = new Robot().createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
try {
    ImageIO.write(screencapture, "jpg", socket.getOutputStream());
    System.out.println("Image should be sent!");
} catch (IOException ex){
    ex.printStackTrace();
} finally {
    if ( socket != null ){
        try { socket.close(); } catch (IOException ex){}
    }
    System.out.println("Image sent and socket closed!");
}

```

There is also a client on the other side, consuming the data being sent by the code above.
The code to do this is:

```
BufferedImage image = ImageIO.read(socket.getInputStream());
JLabel label = new JLabel(new ImageIcon(image));
f.getContentPane().add(label);

```

Now my question is, what is wrong with this code, and how can I make this work?