-
public interface WebSocket
-
-
Method Summary
Modifier and Type Method Description abstract voidclose(int code, String message)sends the closing handshake. abstract voidclose(int code)sends the closing handshake. abstract voidclose()Convenience function which behaves like close(CloseFrame. abstract voidcloseConnection(int code, String message)This will close the connection immediately without a proper close handshake. abstract voidsend(String text)Send Text data to the other end. abstract voidsend(ByteBuffer bytes)Send Binary data (plain bytes) to the other end. abstract voidsend(Array<byte> bytes)Send Binary data (plain bytes) to the other end. abstract voidsendFrame(Framedata framedata)Send a frame to the other end abstract voidsendFrame(Collection<Framedata> frames)Send a collection of frames to the other end abstract voidsendPing()Send a ping to the other end abstract voidsendFragmentedFrame(Opcode op, ByteBuffer buffer, boolean fin)Allows to send continuous/fragmented frames conveniently. abstract booleanhasBufferedData()Checks if the websocket has buffered data abstract InetSocketAddressgetRemoteSocketAddress()Returns the address of the endpoint this socket is connected to, or {@code null}if it isunconnected.abstract InetSocketAddressgetLocalSocketAddress()Returns the address of the endpoint this socket is bound to. abstract booleanisOpen()Is the websocket in the state OPEN abstract booleanisClosing()Is the websocket in the state CLOSING abstract booleanisFlushAndClose()Returns true when no further frames may be submitted This happens before the socketconnection is closed. abstract booleanisClosed()Is the websocket in the state CLOSED abstract DraftgetDraft()Getter for the draft abstract ReadyStategetReadyState()Retrieve the WebSocket 'ReadyState'. abstract StringgetResourceDescriptor()Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1. abstract <T> voidsetAttachment(T attachment)Setter for an attachment on the socket connection. abstract <T> TgetAttachment()Getter for the connection attachment. abstract booleanhasSSLSupport()Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection abstract SSLSessiongetSSLSession()Returns the ssl session of websocket, if ssl/wss is used for this instance. abstract IProtocolgetProtocol()Returns the used Sec-WebSocket-Protocol for this websocket connection -
-
Method Detail
-
close
abstract void close(int code, String message)
sends the closing handshake. may be send in response to an other handshake.
- Parameters:
code- the closing codemessage- the closing message
-
close
abstract void close(int code)
sends the closing handshake. may be send in response to an other handshake.
- Parameters:
code- the closing code
-
close
abstract void close()
Convenience function which behaves like close(CloseFrame.NORMAL)
-
closeConnection
abstract void closeConnection(int code, String message)
This will close the connection immediately without a proper close handshake. The code and themessage therefore won't be transferred over the wire also they will be forwarded toonClose/onWebsocketClose.
- Parameters:
code- the closing codemessage- the closing message
-
send
abstract void send(String text)
Send Text data to the other end.
- Parameters:
text- the text data to send
-
send
abstract void send(ByteBuffer bytes)
Send Binary data (plain bytes) to the other end.
- Parameters:
bytes- the binary data to send
-
send
abstract void send(Array<byte> bytes)
Send Binary data (plain bytes) to the other end.
- Parameters:
bytes- the byte array to send
-
sendFrame
abstract void sendFrame(Framedata framedata)
Send a frame to the other end
- Parameters:
framedata- the frame to send to the other end
-
sendFrame
abstract void sendFrame(Collection<Framedata> frames)
Send a collection of frames to the other end
- Parameters:
frames- the frames to send to the other end
-
sendPing
abstract void sendPing()
Send a ping to the other end
-
sendFragmentedFrame
abstract void sendFragmentedFrame(Opcode op, ByteBuffer buffer, boolean fin)
Allows to send continuous/fragmented frames conveniently. For more into on this frame typesee http://tools.ietf.org/html/rfc6455#section-5.4
If the first frame you send is also the last then it is not a fragmented frame and willreceived via onMessage instead of onFragmented even though it was send by this method.
- Parameters:
op- This is only important for the first frame in the sequence.buffer- The buffer which contains the payload.fin- true means the current frame is the last in the sequence.
-
hasBufferedData
abstract boolean hasBufferedData()
Checks if the websocket has buffered data
-
getRemoteSocketAddress
abstract InetSocketAddress getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or
{@code null}if it isunconnected.
-
getLocalSocketAddress
abstract InetSocketAddress getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to.
-
isOpen
abstract boolean isOpen()
Is the websocket in the state OPEN
-
isClosing
abstract boolean isClosing()
Is the websocket in the state CLOSING
-
isFlushAndClose
abstract boolean isFlushAndClose()
Returns true when no further frames may be submitted This happens before the socketconnection is closed.
-
isClosed
abstract boolean isClosed()
Is the websocket in the state CLOSED
-
getReadyState
abstract ReadyState getReadyState()
Retrieve the WebSocket 'ReadyState'. This represents the state of the connection. It returns anumerical value, as per W3C WebSockets specs.
-
getResourceDescriptor
abstract String getResourceDescriptor()
Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2If the opening handshake has not yet happened it will return null.
-
setAttachment
abstract <T> void setAttachment(T attachment)
Setter for an attachment on the socket connection. The attachment may be of any type.
- Parameters:
attachment- The object to be attached to the user
-
getAttachment
abstract <T> T getAttachment()
Getter for the connection attachment.
-
hasSSLSupport
abstract boolean hasSSLSupport()
Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection
-
getSSLSession
abstract SSLSession getSSLSession()
Returns the ssl session of websocket, if ssl/wss is used for this instance.
-
getProtocol
abstract IProtocol getProtocol()
Returns the used Sec-WebSocket-Protocol for this websocket connection
-
-
-
-