Skip to content

//okhttp/okhttp3/WebSocket/close

close

[jvm]\ abstract fun close(code: Int, reason: String?): Boolean

Attempts to initiate a graceful shutdown of this web socket. Any already-enqueued messages will be transmitted before the close message is sent but subsequent calls to send will return false and their messages will not be enqueued.

This returns true if a graceful shutdown was initiated by this call. It returns false if a graceful shutdown was already underway or if the web socket is already closed or canceled.

Parameters

jvm

code Status code as defined by Section 7.4 of RFC 6455.
reason Reason for shutting down, no longer than 123 bytes of UTF-8 encoded data (not characters) or null.

Throws

kotlin.IllegalArgumentException if code is invalid or reason is too long.