dimanche 20 mai 2018

Sending files through java server by byte[]

I am trying to send files (html, css, and images) through Java server socket. I was able to send html and css, except for images..

ServerSocket ssocket = new ServerSocket(8888);
Socket socket = ssocket.accept();
File fp = new File(file);
byte[] arrByte = new byte[4096];            
FileInputStream fis = new FileInputStream(fp);
OutputStream os = socket.getOutputStream();

int count;
while((count = fis.read(arrByte)) > 0 ) {
    os.write(arrByte, 0, count);                
}

My client (receiver) is the web server. Below is my response header:

        header = "HTTP/1.1 200 OK \n" + 
                "Connection: close \n" + 
                "Date: " + new Date().toString() + " \n" +
                "Content-Type: image/jpg \n" + 
                "Content-Length: " + fp.length() + " \n" + 
                "\r\n";

I can't seem to find which part I am lacking... How do I get the images load to the server?




Aucun commentaire:

Enregistrer un commentaire