Closed ntpanchal closed 2 years ago
Use transports = arrayOf(Polling.NAME, PollingXHR.NAME, WebSocket.NAME)
.
Also in my case:
var socket: Socket? = null
private set
private var hasError = false
// Better use in a background thread.
fun initSocket(): Socket? {
if (socket == null && !hasError) {
val options = getOptions()
socket = try {
IO.socket(SOCKET_URL, options)
} catch (e: RuntimeException) {
// java.lang.RuntimeException: java.net.MalformedURLException: For input string: "...".
hasError = true
null
} catch (e: URISyntaxException) {
hasError = true
null
}
}
return socket
}
fun connect() {
socket?.apply {
if (!connected()) {
connect()
}
}
}
fun disconnect() {
socket?.apply {
if (connected()) {
disconnect()
}
}
}
private fun getOptions(): IO.Options {
// Fixing the error "io.socket.engineio.client.EngineIOException: xhr poll error".
IO.setDefaultOkHttpWebSocketFactory(okHttpClient)
IO.setDefaultOkHttpCallFactory(okHttpClient)
return IO.Options().apply {
forceNew = true
reconnectionAttempts = Integer.MAX_VALUE;
reconnection = true
secure = true
timeout = 1000
transports = arrayOf(Polling.NAME, PollingXHR.NAME, WebSocket.NAME)
query = "..." // For authorization.
}
}
Don't forget to connect to the socket after initialization. To set okHttpClient
see https://stackoverflow.com/a/60507560/2914140.
Closed due to inactivity, please reopen if needed.
I have read the ReadMe file and according to that used library version 0.9.0
I have also added Trust Manager to okhttpclient using the following code using this
How to overcome this issue any idea?