Open
Description
Hello, I'm trying to integrate socket.io in my Kotlin application but when I launch it, it doesn't look like it's trying to connect to the server.
What I tried:
This is my client-side code:
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import io.socket.client.IO
import io.socket.client.Socket
import io.socket.emitter.Emitter
import java.lang.Exception
class MainActivity : AppCompatActivity() {
lateinit var socket: Socket
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
try {
socket = IO.socket("http://address:port/")
socket.on(Socket.EVENT_CONNECT) {
println("Socket connected")
}
socket.connect()
} catch (ex:Exception) {
println(ex)
}
}
}
And back in nodejs:
and express = require('express')
let app = express()
let http = require('http').createServer(app)
let io = require('socket.io')(http)
const path = require('path')
app.use(express.static(path.join(__dirname, "public")))
app.get('/', (req, res) => {
res.send ("you shouldn't be here")
})
io.on('connection', (socket) => {
console.log('new user')
})
io.on('foo', (data) => {
console.log(data)
})
http.listen(5624, () => {
console.log('listening on localhost:5624')
})
I also tried to open a C socket, same problem, when I use the javascript client I receive data but when I try from the application, no connection attempt is made.
Is my code no good? It's from an official tutorial.
Devices:
Client: Oneplus 7 on Android Q.
Server: VPS on archlinux.