Class WebSocketImpl
java.lang.Object
com.codename1.impl.WebSocketImpl
Platform contract behind the public com.codename1.io.WebSocket facade.
Each port that supports WebSocket subclasses this and is returned from
CodenameOneImplementation.createWebSocketImpl(String).
Subclasses call sink().onConnect(), sink().onTextMessage(...), etc.
from whichever thread the native layer fires the event on. The sink is
set exactly once, by the facade, before connect(int) is called.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract voidclose()Close the connection.abstract voidconnect(int connectTimeoutMs) Initiate the connection.abstract WebSocketStateThe subprotocol the server selected, or null when none was negotiated (or the connection has not completed yet).final StringgetUrl()protected final String[]The subprotocols the client offered, or null when none were set.abstract voidsendBinary(byte[] message) abstract voidfinal voidfinal voidsetRequestedSubprotocols(String[] protocols) Sets the subprotocols (RFC 6455Sec-WebSocket-Protocol) the client offers, in preference order.protected final voidsetSelectedSubprotocol(String protocol) Records the subprotocol the server selected.protected final WebSocketEventSinksink()
-
Constructor Details
-
WebSocketImpl
-
-
Method Details
-
getUrl
-
setEventSink
-
sink
-
setRequestedSubprotocols
Sets the subprotocols (RFC 6455Sec-WebSocket-Protocol) the client offers, in preference order. Called by the public facade beforeconnect(int); ports include them in the handshake. Null or empty means "no subprotocol negotiation". -
requestedSubprotocols
The subprotocols the client offered, or null when none were set. Ports read this while building the handshake. -
setSelectedSubprotocol
Records the subprotocol the server selected. Ports call this once the handshake completes, before firingsink().onConnect(), so the value is visible to the user's connect handler. -
getSelectedSubprotocol
The subprotocol the server selected, or null when none was negotiated (or the connection has not completed yet). -
connect
public abstract void connect(int connectTimeoutMs) Initiate the connection. May return immediately and complete asynchronously; success is signalled viasink().onConnect().- Parameters:
connectTimeoutMs- handshake timeout in milliseconds, or 0 for the platform default.
-
close
public abstract void close()Close the connection. Idempotent -- calling on an already-closed connection is a no-op. -
sendText
-
sendBinary
public abstract void sendBinary(byte[] message) -
getReadyState
-