Reputation: 2645
Am getting set socket option failed exception in Android. What am I doing wrong ?
setsockopt failed: EBADF (Bad file number)
For the following code:
int timeout = 500;
Socket socket = new Socket(InetAddress.getByAddress(new byte[]{10, 0, 2, 2}),
Integer.parseInt(m.destPort));
ObjectOutputStream oos = new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(m);
oos.close();
socket.setSoTimeout(timeOut);
ObjectInputStream iis = new ObjectInputStream(socket.getInputStream());
iis.readObject();
iis.close();
socket.close();
Upvotes: 1
Views: 454
Reputation: 311002
Closing the input or output stream of a socket closes the other stream and the socket.
Change
oos.close();
to
oos.flush();
(Poor coding in Android. It should throw a SocketException: socket closed.
)
Upvotes: 3