简体   繁体   中英

Sending object over socket - object contains bufferedimage- Any ideas?

Im sending a object over a socket, an object of the following class:

public class ClientDetail implements Serializable{
public String username;
public String [] capturedText;
public String site;
public BufferedImage screenShot; 
 }

and I am trying to send it using the following:

        ClientDetail cD = new ClientDetail();
        cD.capturedText = mon.getCapturedText();
        cD.username = username;
        cD.site = mon.getWebsite();
        ScreenShot ss = new ScreenShot();
        cD.screenShot = ss.getScreenShot();

        if(mon.isCaptured)
        {
            try{
                output.writeObject(cD);
                output.flush(); 
            }catch(IOException ex){
                System.out.println("\nSomething messed up sending the message!");
            }
        }

This is failing to send. Can you send an object that contains a image over a socket?

Send thing:

ImageIO.write((RenderedImage) image, "png", output);

Receiver thing you know:

ImageIO.read(input);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM