Not connecting to socket on IOS version
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
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]