Read Image File Through Java Socket

后端 未结 1 1211
死守一世寂寞
死守一世寂寞 2020-12-07 05:02

This is what I have so far,

Socket clientSocket = new Socket(HOST, PORT);

ByteArrayOutputStream buffer = new ByteArrayOutputStream();

InputStream is = sock         


        
相关标签:
1条回答
  • 2020-12-07 05:52

    Why you don't want to use simple http URL to get image from host? I mean:

    URL imageURL = new URL("http://host:port/address");
    BufferedImage bufferedImage = ImageIO.read(imageURL);
    

    If you want to use plain socket you have to parse http response and extract data from the http reply manually: read/skip headers, read binary data and pass it to ImageIO.read (or seek stream to correct position and pass stream to ImageIO.read).

    0 讨论(0)
提交回复
热议问题