Results 1 to 4 of 4
  1. #1
    maheshsk is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default Sending image file over serversocket to browser client

    Hello All,

    I am writing simple web server which accepts requests on socket and sends html text response.
    I am receiving requests from browser on the specified port. like
    Now I also want to send small gif files and want to display them on the browser page. The resulting html page will display text combined with gif images at specific positions.
    I am using java ImageIO API for the same. However I am not getting the desired page.

    Here is my sample code on Server side: I am listening to requests on serverSocket 5555

    PrintWriter socketWriter = new PrintWriter(socket.getOutputStream());
    socketWriter.println("HTTP/1.1 " + 200 + " OK");
    socketWriter.println("Server: ICS HTTP Server");
    socketWriter.println("Date: " + (new Date()));
    socketWriter.println("Content-type: text/html");
    socketWriter.println("Content-type: image/jpeg");
    socketWriter.println("Content-type: image/gif");
    socketWriter.println("Cache-Control,no-store,no-cache,must-revalidate");

    socketWriter.println("Content-Length: " + output.length());
    socketWriter.println("");

    //String output is much more with combination of havascript,html and html tables

    socketWriter.println(output);

    String filePath = c:\images\+ "button1.gif";
    File f1 = new File(filePath);

    ImageInputStream imgStream1 = ImageIO.createImageInputStream(f1);
    long size = imgStream1.length();

    BufferedImage bufferedImage1 = ImageIO.read(f1);
    boolean success = ImageIO.write(bufferedImage1,"gif",socket.getOutpu tStream());

    socketWriter.close();
    socketReader.close();
    socket.close();
    socket = null;

    I will appreciate your help and thanks in advance.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    maheshsk is offline Member
    Join Date
    Dec 2009
    Posts
    4
    Rep Power
    0

    Default sorry about that

    Sorry about that. I will take care of it next time. I thought I have to put question under different topics. As my question was generic, I could not understand where to add it.

  4. #4
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

Similar Threads

  1. Client Socket Fails to Connect to ServerSocket
    By Sir_Fz in forum Networking
    Replies: 4
    Last Post: 11-03-2009, 08:44 AM
  2. sending to client
    By rob in forum New To Java
    Replies: 1
    Last Post: 02-22-2009, 12:07 PM
  3. Replies: 1
    Last Post: 02-10-2009, 10:16 AM
  4. sending image file from JSP to Servlet
    By ravian in forum Advanced Java
    Replies: 2
    Last Post: 01-10-2008, 03:34 PM
  5. sending jar files from client to server?
    By gobinathm in forum New To Java
    Replies: 2
    Last Post: 11-13-2007, 06:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •