moko-socket-io icon indicating copy to clipboard operation
moko-socket-io copied to clipboard

Not connecting to socket on IOS version

Open Usama99786 opened this issue 7 months ago • 1 comments

 val socket = Socket(
        endpoint = "http://handwi.com:4005",
        config = SocketOptions(
            queryParams = mapOf("" to ""),
            transport = SocketOptions.Transport.DEFAULT
        )
    ) {
        on(SocketEvent.Connect) {
            println("SocketConnected123")
            val payload = buildJsonObject {
                put("search", "")
                put("page", "1")
                put("limit", "20")
                put("user_id", "28")
                put("last_read_time", "")
            }

          emit("get_posts", payload)
        }

        on(SocketEvent.Connecting) {
            println("connecting")
        }

        on(SocketEvent.Disconnect) {
            println("disconnect")
        }

        on(SocketEvent.Error) {
            println("error ${it.cause}")
            println("error123 ${it.message}")
        }

        on(SocketEvent.Reconnect) {
            println("reconnect")
        }

        on(SocketEvent.ReconnectAttempt) {
            println("reconnect attempt $it")
        }

        on(SocketEvent.Ping) {
            println("ping")
        }

        on(SocketEvent.Pong) {
            println("pong")
        }

        on("observePublicPosts") { data ->
            println("SocketData1234: $data")

                try {
                    val postsResponse = Json.decodeFromString<PostsResponse>(data)
                    _posts.value = postsResponse.postCollection ?: emptyList()
                    preCacheVideos(postsResponse)
                } catch (e: Exception) {
                    println("❌ Failed to parse JsonElement: ${e.message}")
                }

        }
    }
    socket.connect()

error null error123 Error reconnect attempt 1 error null error123 Error reconnect attempt 2 error null error123 Error reconnect attempt 3

i am unable to connect to my socket in IOS app, inn android it is working fine

Usama99786 avatar Jun 09 '25 20:06 Usama99786

The current version of the socket io client library for IOS (socketio/socket.io-client-swift:15.x) does not yet support socket io server version 3.x.

Rationale: There was a problem with the default namespace declaration under the new protocol. If you enable debug mode, you will see that Socket server still receives message from client but events such as on connection, emit are not triggered.

Solution: Downgrade your NodeJS socket io server version to version 2.x

Eg: npm install [email protected]

elboudi-a avatar Sep 19 '25 16:09 elboudi-a