AWebSocket

class AWebSocket(url: String, okHttpClient: OkHttpClient) : IWebSocket

AWebSocket:一个基于okhttp封装的 WebSocket 客户端,轻量易用。

Author

Jenly

Follow me

Constructors

Link copied to clipboard
constructor(url: String)
constructor(url: String, okHttpClient: OkHttpClient)

Types

Link copied to clipboard
object Companion

Functions

Link copied to clipboard
open override fun addHeader(name: String, value: String)

添加请求头;需在调用connect函数之前添加请求头才有效

Link copied to clipboard
open override fun close(): Boolean
open override fun close(code: Int, reason: String): Boolean

关闭

Link copied to clipboard
open override fun connect()

连接

Link copied to clipboard
fun getConnect(): WebSocket?

获取 WebSocket

Link copied to clipboard
open override fun getReadyState(): ReadyState

获取WebSocket的连接状态;更多详细状态可参见:ReadyState

Link copied to clipboard
open override fun isClosed(): Boolean

是否已经关闭;更多详细状态可参见:ReadyState

Link copied to clipboard
open override fun isClosing(): Boolean

是否正在关闭中;更多详细状态可参见:ReadyState

Link copied to clipboard
open override fun isOpen(): Boolean

连接是否已打开;更多详细状态可参见:ReadyState

Link copied to clipboard
open override fun reconnect()

重新连接

Link copied to clipboard
open override fun removeHeader(name: String)

移除请求头;需在调用connect函数之前移除请求头才有效

Link copied to clipboard
open override fun send(text: String): Boolean

发送消息;文本消息(类型:0x01)

open override fun send(bytes: ByteString): Boolean

发送消息;二进制消息(类型:0x02)

Link copied to clipboard
open override fun setWebSocketListener(listener: WebSocketListener?)

设置WebSocket监听