I get this exception on Android using SocketIo, everytime when internet gets disconnected (I turn off wifi). I cant find the reason, please help :
This is exception is to be expected any time an SSLSocket read fails due to an unavailable network. Socket.IO clients may safely ignore it.
As you might expect, disabling a network while you are using it causes I/O errors. In Java, this produces an IOException of one kind or another. If you had been using "normal" sockets, this would have been a SocketException, and you would have seen the same sort of message ("software caused connection abort"). Since, in this case, you are using an HTTPS connection, the IOException is an SSLException (which wraps the error encountered by the lower-level TCP socket).
Any IOExceptions thrown by the TCP socket will cause SSLExceptions on the SSLSocket, at least until such time as the SSLSocket is properly closed.
Related
When OkHttp3 calls the onFailure callback, it passes an IOException. Is there a specific subclass of IOException that will indicate that the target device has disappeared from the WiFi network? Is there another way to detect this?
IOException has several sub-classes; while it may be save to assume that something went offline - because when the own network connection is still alive, it has to be the other side of the connection. when it throws an IOException, that's an IOExcpetion; casting it won't add any more information.
the state of the own network connection can be detected, but not with OkHttp3. here's an example for that on my GitHub; see class ConnectivityListener and class ConnectivityReceiver.
How would you detect the state of another host's network connection?
this can be tested, by switching off the WiFi network of either device; both situations would cause an IOException.
i am using javamail's SMTPTransport.sendMessage method to send emails in my android app and everything works fine... but when i start sending a message and in the middle, i disable my wifi, it gets stuck. I have waited for more than 1hour now and it is still stuck; no exception is thrown... any idea how to handle this situation?
edit:
i have added a timeout
props.put("mail.smtp.connectiontimeout", "3000");
props.put("mail.smtp.timeout", "3000");
does not seem to work ... i have simulated a connection loss and it's already 5mins now and it is still in sending state and has not timed out
edit2:
timeout/error(not even sure if it is a timeout) occurred after 16mins
06-30 18:47:27.722: I/System.out(15906): javax.net.ssl.SSLException: Write error: ssl=0xdf8268: I/O error during system call, Invalid argument
edit 3:
it does not always throw an exception... i have simulated a connection loss and after 1hr, still no exception... it is in sending state..... and have not return yet :(
The current version of JavaMail only handles timeouts for reads, because that's all the JDK supports. For the next JavaMail release I've added support for write timeouts. You can experiment with it using the 1.5.1-SNAPSHOT release of JavaMail available in the maven.java.net repository. You'll need to set the "mail.smtp.writetimeout" property. Don't know if this will help you on Android since it's not really Java...
I tried connecting to an IP address (e.g. http://222.222.222.222:8080) and a URL (e.g. http://www.website.com) while my wiFi is disabled. I noticed that if I don't have a wiFi and I tried connecting to an IP address, it gives me a ConnectException error. On the other hand, if I don't have a wiFi and I tried connecting to a URL, it gives me an IOException error. Why am I receiving different Exception for the 2 cases when the only difference is I supplied an IP address for the first one and a URL for the other? Can someone enlighten me on this one? I am asking this for clarification.
Thank you!
You're getting different errors because different steps are failing.
When you're trying to connect to port 80 of an IP address, it is a connect(2) system call that is failing. There are many different reasons why connect(2) could fail; you'll need to inspect the message from the exception to provide a good error message to the user.
When you're trying to connect to port 80 of a textual address, the libraries will first try to resolve the hostname into an IP address using getaddrinfo(3). The name resolution may or may not fail based on having network access -- if you were trying to connect to localhost, for example, no network access is usually required, as the nameservice lookup can be handled entirely on the local device. Because the nameservice failure happens because you cannot contact a nameserver, it makes sense to give a different error message (and exception), even if the underlying cause is the same for a given set of tests. You might not be able to contact the nameservers for any variety of reasons. Again, you'll need to inspect the message from the exception to give a good error message to the user.
When I am sending real time audio from udp socket then there is an exception throw java.net.BindException : cannot assign requested address. Why?
Check that the port you are specifying is not used by some other process. And you are specifying that exception is occurring when you are sending packet, but I think it might be occurring at socket creation time.
Im trying to determine if data was successfully sent to the server through a TCP socket using the OutputStream object. for testing purposes i disable network communications in the phone and OutputStream.write(); doesn't throw an exception, all the methods in the socket class return as though the socket is active and working. Is there anything i'm doing wrong here?
is there any socket implementation or stream implementation i can use to get an exception or error when the stream / socket doesn't actually send the data in the buffer?
also setting SetSoTimeout() on the socket doesn't seem to do anything.
Thanks,
Totem
If you're using the emulator this is a known bug, data can still be sent after enabling airplane mode.