CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-com-squareup-okhttp3--okhttp

Square's meticulous HTTP client for Java and Kotlin

Pending
Overview
Eval results
Files

websockets.mddocs/

WebSocket Support

WebSocket protocol support for real-time bidirectional communication.

WebSocket Interface

interface WebSocket {
    fun request(): Request
    fun queueSize(): Long
    fun send(text: String): Boolean
    fun send(bytes: ByteString): Boolean
    fun close(code: Int, reason: String?): Boolean
    fun cancel()
}

WebSocketListener

abstract class WebSocketListener {
    open fun onOpen(webSocket: WebSocket, response: Response) {}
    open fun onMessage(webSocket: WebSocket, text: String) {}
    open fun onMessage(webSocket: WebSocket, bytes: ByteString) {}
    open fun onClosing(webSocket: WebSocket, code: Int, reason: String) {}
    open fun onClosed(webSocket: WebSocket, code: Int, reason: String) {}
    open fun onFailure(webSocket: WebSocket, t: Throwable, response: Response?) {}
}

WebSocket Example

val listener = object : WebSocketListener() {
    override fun onMessage(webSocket: WebSocket, text: String) {
        println("Received: $text")
    }
}

val request = Request.Builder().url("wss://echo.websocket.org").build()
val webSocket = client.newWebSocket(request, listener)
webSocket.send("Hello WebSocket!")

Install with Tessl CLI

npx tessl i tessl/maven-com-squareup-okhttp3--okhttp

docs

caching.md

cookies.md

forms-multipart.md

http-client.md

index.md

interceptors.md

networking.md

requests-responses.md

security.md

urls.md

websockets.md

tile.json