RazzleFnDazzle
Well-Known Member
I am sending an image from my android device to my computer using a socket. The servers are communicating fine but when the file reaches the computer it cannot be opened to view. Is there is some sort of reason why it won't be a direct byte copy from my phone to my computer? I've spent hours on this modifying a bit by bit and I can't get anything to work. It seems pretty straight forward, but I must be doing something wrong.
Code Snippets:
Client:
Server:
Code Snippets:
Client:
Code:
FileInputStream is;
Socket socket;
ObjectOutputStream objectOutputStream = new ObjectOutputStream(socket.getOutputStream());
//send an object with data first here
objectOutputStream.flush();
byte[] b = new byte[socket.getSendBufferSize()];
int read = 0;
while ((read = is.read(b)) != -1) {
objectOutputStream.write(b, 0, read);
objectOutputStream.flush();
b = new byte[socket.getSendBufferSize()];
}
objectOutputStream.close();
is.close();
socket.close();
Server:
Code:
Socket socket;
ObjectInputStream reader;
FileOutputStream fos;
//received object with data handled it
byte[] b = new byte[socket;.getReceiveBufferSize()];
int read = 0;
while ((read = reader.read(b)) != -1) {
fos.write(b, 0, read);
fos.flush();
b = new byte[socket;.getReceiveBufferSize()];
}
fos.close();