Results 1 to 2 of 2
- 12-10-2009, 02:16 PM #1Member
- Join Date
- Dec 2009
- Rep Power
Sending image file over serversocket to browser client
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.
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-Length: " + output.length());
//String output is much more with combination of havascript,html and html tables
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());
socket = null;
I will appreciate your help and thanks in advance.
- By maheshsk in forum NetworkingReplies: 3Last Post: 12-10-2009, 04:49 PM
- By Sir_Fz in forum NetworkingReplies: 4Last Post: 11-03-2009, 08:44 AM
- By rob in forum New To JavaReplies: 1Last Post: 02-22-2009, 12:07 PM
- By amita_k29 in forum NetworkingReplies: 1Last Post: 02-10-2009, 10:16 AM
- By ravian in forum Advanced JavaReplies: 2Last Post: 01-10-2008, 03:34 PM