Socket.kt 724 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
package com.example.tolucagraphics

import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import java.util.concurrent.TimeUnit

object Socket {

    var username: String?= null
    var SERVER_PATH: String?= null
    private val client = OkHttpClient.Builder()
        .readTimeout(1, TimeUnit.SECONDS)
        .build()

    var request : Request?=null
    lateinit var listener : WebSocketListener
    fun realizarConex() {
        request = Request.Builder()
            .url(SERVER_PATH + username)
            .build()
    }
    var webSocketSingle : WebSocket?=null
    fun conectarconWS(){
        webSocketSingle = client.newWebSocket(request!!, listener)
    }
}