简体   繁体   中英

Java socket io client fail to connect to socket io nodejs server

I am using v4 of socket-io nodejs server. I am using v2 of java socket-io client.

private val uri: URI = URI.create("MY_URL")
    private val options: IO.Options = IO.Options.builder() // IO factory options
        .setForceNew(false)
        .setMultiplex(true) // low-level engine options
        .setTransports(arrayOf(Polling.NAME, WebSocket.NAME))
        .setUpgrade(true)
        .setRememberUpgrade(false)
        .setQuery(null)
        .setExtraHeaders(null) // Manager options
        .setReconnection(true)
        .setReconnectionAttempts(Int.MAX_VALUE)
        .setReconnectionDelay(1000)
        .setReconnectionDelayMax(5000)
        .setRandomizationFactor(0.5)
        .setTimeout(20000) // Socket options
        .setAuth(null)
        .build()
    val socket: Socket = IO.socket(uri,options)

socket.connect()

        socket.emit("userjoin","abc@gmail.com")

        socket.on("userjoined") { args ->
            statusText.text = args[0].toString()
        }

        socket.on("disconnected") { args ->
            statusText.text = args[0].toString()
        }

        socket.on("receiveMessage") { args ->
            Log.i("receiveMessage",args[0].toString())
            Log.i("receiveMessage",args[1].toString())
            msgsText.append("${args[0]}\n")
        }

Nothing really happens. No error msgs.There are definitely no issues from server side as our web app which uses reactjs and socket-io client library for web is able to connect to the server and pass messages. I am not able to figure out what exactly is going wrong.

我在 js 客户端和烧瓶服务器上遇到了同样的问题,我检查了日志,这是一个超时错误,你看起来像是一个超时错误,因为它没有响应。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM