0

I have a VPN service inside my application and I have also created a connection socket through the socket.io-client library, which I want to connect directly and not go through the vpn tunnel. I know that for this I have to use protect() method of the VpnService class, but the value it takes is Integer and I don't know what exactly to put inside it.

Socket codes:

        SocketHandler.setSocket()
        SocketHandler.establishConnection()

        val mSocket = SocketHandler.getSocket()
        mSocket.on("result") { args ->
            if (args[0] != null) {
                val result = args[0] as String
                runOnUiThread {

                    if(result == "relogin") {
                        Log.d("RESULT", result)
                    }
                }
            }
        }

SocketHandler object:

object SocketHandler {

    lateinit var mSocket: Socket

    @Synchronized
    fun setSocket() {
        try {
            mSocket = IO.socket("http://172.19.0.1:3001")
        } catch (e: URISyntaxException) {
        }
    }

    @Synchronized
    fun getSocket(): Socket {
        return mSocket
    }

    @Synchronized
    fun establishConnection() {
        mSocket.connect()
    }

    @Synchronized
    fun closeConnection() {
        mSocket.disconnect()
    }
}

I tried to use mSocket.id() but the value is String.

Fardin
  • 21
  • 1
  • 3

0 Answers0