So I've made an App which should allow my phone to send an Image to my computer. I've made another app before, which was a bit easier and everythiong worked fine. In the new App, the only difference is that the image is being cropped before it is sent to my pc, the networking code stayed the same and I'm really furious right now because I just cant figure out why it does not work... I always get a TimeOut Exception which I dont understand. I tried turning off the firewall and stuff like that but nothing works. (This is the code in Android Studio to send the Image)
Heres my Code for sending the Image:
new Thread() {
public void run() {
Socket socket = null;
try {
socket = new Socket(host, 6245);
System.out.println("socket successfully opened!");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, baos);
InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
OutputStream outputStream = socket.getOutputStream();
byte[] buffer = new byte[4096];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
outputStream.write(buffer, 0, bytesRead);
}
outputStream.close();
inputStream.close();
socket.close();
System.out.println("Photo sended successfully.");
} catch (IOException e) {
e.printStackTrace();
socket.close();
}
}
}.start();
This code must be the problem, since the server-side code works for the other app, which uses the exact same code to send the file and I didn't change anything whatsoever. Thank you for helping!