Associate
Hi, I've managed to get most of my client and server program working in Java but the next part involves sending an image between the client and server...
I've googled around and so far I've come across a few examples such as...
// Server code
FileInputStream fis = new FileInputStream("images\\picture.jpg");
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
ObjectOutputStream oos = new ObjectOutputStream(serverSocket.getOutputStream()) ;
oos.writeObject(buffer);
// Client code
ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
byte[] buffer = (byte[])ois.readObject();
FileOutputStream fos = new FileOutputStream("downloaded\\picture.jpg");
fos.write(buffer);
Edit: got the directory stuff working... c:/client and c:/server worked fine :/ sure it didn't the first time lol
And also once i've got it to transfer from client to server, the email parts were being stored in a Vector String[] soo "[email protected]", "subject", "body" I'm guessing once the file has been transfered to the server, you just have a directory of where it is on the server like "serverimages\\picture.jpg" inside the String[] and then send that across to the client?
Edit2: How can you check what kind of file it is? perhaps send the file extension across?
Thanks
I've googled around and so far I've come across a few examples such as...
// Server code
FileInputStream fis = new FileInputStream("images\\picture.jpg");
byte[] buffer = new byte[fis.available()];
fis.read(buffer);
ObjectOutputStream oos = new ObjectOutputStream(serverSocket.getOutputStream()) ;
oos.writeObject(buffer);
// Client code
ObjectInputStream ois = new ObjectInputStream(clientSocket.getInputStream());
byte[] buffer = (byte[])ois.readObject();
FileOutputStream fos = new FileOutputStream("downloaded\\picture.jpg");
fos.write(buffer);
Edit: got the directory stuff working... c:/client and c:/server worked fine :/ sure it didn't the first time lol
And also once i've got it to transfer from client to server, the email parts were being stored in a Vector String[] soo "[email protected]", "subject", "body" I'm guessing once the file has been transfered to the server, you just have a directory of where it is on the server like "serverimages\\picture.jpg" inside the String[] and then send that across to the client?
Edit2: How can you check what kind of file it is? perhaps send the file extension across?
Thanks
Last edited: