SimpleCoder
SimpleCoder

Reputation: 33

Socket is closed - Android AsyncTask

I have problem with receiving response from server. My app takes picture, sends it to server and waits for response. Unfortunately I get socket is closed exception whenever I try to receive response in Inputstream. I am struggling with this for 2 days. I wast trying different types of Input and Output streams but I have no idea whi this is happening. I was trying different solutions from other similar topics but none of them works. I am not good in Android because this is one of my first apps.

Upvotes: 0

Views: 205

Answers (2)

Mayank Sharma
Mayank Sharma

Reputation: 2835

java.net.SocketException arises only when u close the OutputStream (or) Socket before reading from the server.so check your code

Upvotes: 0

OneCricketeer
OneCricketeer

Reputation: 191854

OutputSteam#close()

Closes this output stream and releases any system resources associated with this stream

You are closing the OutputSteam before getting the InputStream (which is where the error is thrown.

I'd recommend closing your socket and streams in the finally block.

Upvotes: 1

Related Questions