Top Methods
org.java_websocket

public Interface WebSocket

Known Direct Implementers
org.java_websocket.WebSocketImpl, org.java_websocket.client.WebSocketClient
Imports
java.net.InetSocketAddress, java.nio.ByteBuffer, java.util.Collection, javax.net.ssl.SSLSession, org.java_websocket.drafts.Draft, org.java_websocket.enums.Opcode, .ReadyState, org.java_websocket.exceptions.WebsocketNotConnectedException, org.java_websocket.framing.Framedata, org.java_websocket.protocols.IProtocol

Method Summary

Modifier and TypeMethod and Description
public void
close(int
the closing code
code
,
String
the closing message
message
)

sends the closing handshake.

public void
close(int
the closing code
code
)

sends the closing handshake.

public void
close()

Convenience function which behaves like close(CloseFrame.NORMAL)

public void
closeConnection(int
the closing code
code
,
String
the closing message
message
)

This will close the connection immediately without a proper close handshake.

public <
The type of the attachment
T
>
T

Returns:

Returns the user attachment
getAttachment
()

Getter for the connection attachment.

public Draft

Returns:

the used draft
getDraft
()

Getter for the draft

public InetSocketAddress

Returns:

the local socket address or null, if this socket is not bound
getLocalSocketAddress
()

Returns the address of the endpoint this socket is bound to, or null if it is not bound.

public IProtocol

Returns:

the Sec-WebSocket-Protocol or null, if no draft available
getProtocol
()

Returns the used Sec-WebSocket-Protocol for this websocket connection

public ReadyState

Returns:

Returns '0 = CONNECTING', '1 = OPEN', '2 = CLOSING' or '3 = CLOSED'
getReadyState
()

Retrieve the WebSocket 'ReadyState'.

public InetSocketAddress

Returns:

the remote socket address or null, if this socket is unconnected
getRemoteSocketAddress
()

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

public String

Returns:

Returns the decoded path component of this URI.
getResourceDescriptor
()

Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2 If the opening handshake has not yet happened it will return null.

public SSLSession

Returns:

the ssl session of this websocket instance
getSSLSession
()

Returns the ssl session of websocket, if ssl/wss is used for this instance.

public boolean

Returns:

has the websocket buffered data
hasBufferedData
()

Checks if the websocket has buffered data

public boolean

Returns:

true, if the websocket does use wss and therefore has a SSLSession
hasSSLSupport
()

Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection

public boolean

Returns:

state equals ReadyState.CLOSED
isClosed
()

Is the websocket in the state CLOSED

public boolean

Returns:

state equals ReadyState.CLOSING
isClosing
()

Is the websocket in the state CLOSING

public boolean

Returns:

true when no further frames may be submitted
isFlushAndClose
()

Returns true when no further frames may be submitted This happens before the socket connection is closed.

public boolean

Returns:

state equals ReadyState.OPEN
isOpen
()

Is the websocket in the state OPEN

public void
send(String
the text data to send
text
)

Send Text data to the other end.

public void
send(ByteBuffer
the binary data to send
bytes
)

Send Binary data (plain bytes) to the other end.

public void
send(byte[]
the byte array to send
bytes
)

Send Binary data (plain bytes) to the other end.

public void
sendFragmentedFrame(Opcode
This is only important for the first frame in the sequence. Opcode.TEXT, Opcode.BINARY are allowed.
op
,
ByteBuffer
The buffer which contains the payload. It may have no bytes remaining.
buffer
,
boolean
true means the current frame is the last in the sequence.
fin
)

Allows to send continuous/fragmented frames conveniently.

public void
sendFrame(Framedata
the frame to send to the other end
framedata
)

Send a frame to the other end

public void
sendFrame(Collection<Framedata>
the frames to send to the other end
frames
)

Send a collection of frames to the other end

public void
sendPing()

Send a ping to the other end

public <
The type of the attachment
T
>
void
setAttachment(T
The object to be attached to the user
attachment
)

Setter for an attachment on the socket connection.

Method Detail

closeback to summary
public void close(int code, String message)

sends the closing handshake. may be send in response to an other handshake.

Parameters
code:int

the closing code

message:String

the closing message

closeback to summary
public void close(int code)

sends the closing handshake. may be send in response to an other handshake.

Parameters
code:int

the closing code

closeback to summary
public void close()

Convenience function which behaves like close(CloseFrame.NORMAL)

closeConnectionback to summary
public void closeConnection(int code, String message)

This will close the connection immediately without a proper close handshake. The code and the message therefore won't be transferred over the wire also they will be forwarded to onClose/onWebsocketClose.

Parameters
code:int

the closing code

message:String

the closing message

getAttachmentback to summary
public <T> T getAttachment()

Getter for the connection attachment.

Parameters
<T>
The type of the attachment
Returns:T

Returns the user attachment

Since
1.3.7
getDraftback to summary
public Draft getDraft()

Getter for the draft

Returns:Draft

the used draft

getLocalSocketAddressback to summary
public InetSocketAddress getLocalSocketAddress()

Returns the address of the endpoint this socket is bound to, or null if it is not bound.

Returns:InetSocketAddress

the local socket address or null, if this socket is not bound

getProtocolback to summary
public IProtocol getProtocol()

Returns the used Sec-WebSocket-Protocol for this websocket connection

Returns:IProtocol

the Sec-WebSocket-Protocol or null, if no draft available

Exceptions
IllegalArgumentException:
the underlying draft does not support a Sec-WebSocket-Protocol
Since
1.5.2
getReadyStateback to summary
public ReadyState getReadyState()

Retrieve the WebSocket 'ReadyState'. This represents the state of the connection. It returns a numerical value, as per W3C WebSockets specs.

Returns:ReadyState

Returns '0 = CONNECTING', '1 = OPEN', '2 = CLOSING' or '3 = CLOSED'

getRemoteSocketAddressback to summary
public InetSocketAddress getRemoteSocketAddress()

Returns the address of the endpoint this socket is connected to, or null if it is unconnected.

Returns:InetSocketAddress

the remote socket address or null, if this socket is unconnected

getResourceDescriptorback to summary
public String getResourceDescriptor()

Returns the HTTP Request-URI as defined by http://tools.ietf.org/html/rfc2616#section-5.1.2
If the opening handshake has not yet happened it will return null.

Returns:String

Returns the decoded path component of this URI.

getSSLSessionback to summary
public SSLSession getSSLSession() throws IllegalArgumentException

Returns the ssl session of websocket, if ssl/wss is used for this instance.

Returns:SSLSession

the ssl session of this websocket instance

Exceptions
IllegalArgumentException:
the underlying channel does not use ssl (use hasSSLSupport() to check)
Since
1.4.1
hasBufferedDataback to summary
public boolean hasBufferedData()

Checks if the websocket has buffered data

Returns:boolean

has the websocket buffered data

hasSSLSupportback to summary
public boolean hasSSLSupport()

Does this websocket use an encrypted (wss/ssl) or unencrypted (ws) connection

Returns:boolean

true, if the websocket does use wss and therefore has a SSLSession

Since
1.4.1
isClosedback to summary
public boolean isClosed()

Is the websocket in the state CLOSED

Returns:boolean

state equals ReadyState.CLOSED

isClosingback to summary
public boolean isClosing()

Is the websocket in the state CLOSING

Returns:boolean

state equals ReadyState.CLOSING

isFlushAndCloseback to summary
public boolean isFlushAndClose()

Returns true when no further frames may be submitted
This happens before the socket connection is closed.

Returns:boolean

true when no further frames may be submitted

isOpenback to summary
public boolean isOpen()

Is the websocket in the state OPEN

Returns:boolean

state equals ReadyState.OPEN

sendback to summary
public void send(String text)

Send Text data to the other end.

Parameters
text:String

the text data to send

Exceptions
WebsocketNotConnectedException:
websocket is not yet connected
sendback to summary
public void send(ByteBuffer bytes)

Send Binary data (plain bytes) to the other end.

Parameters
bytes:ByteBuffer

the binary data to send

Exceptions
IllegalArgumentException:
the data is null
WebsocketNotConnectedException:
websocket is not yet connected
sendback to summary
public void send(byte[] bytes)

Send Binary data (plain bytes) to the other end.

Parameters
bytes:byte[]

the byte array to send

Exceptions
IllegalArgumentException:
the data is null
WebsocketNotConnectedException:
websocket is not yet connected
sendFragmentedFrameback to summary
public void sendFragmentedFrame(Opcode op, ByteBuffer buffer, boolean fin)

Allows to send continuous/fragmented frames conveniently.
For more into on this frame type see 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 will received via onMessage instead of onFragmented even though it was send by this method.

Parameters
op:Opcode

This is only important for the first frame in the sequence. Opcode.TEXT, Opcode.BINARY are allowed.

buffer:ByteBuffer

The buffer which contains the payload. It may have no bytes remaining.

fin:boolean

true means the current frame is the last in the sequence.

sendFrameback to summary
public void sendFrame(Framedata framedata)

Send a frame to the other end

Parameters
framedata:Framedata

the frame to send to the other end

sendFrameback to summary
public void sendFrame(Collection<Framedata> frames)

Send a collection of frames to the other end

Parameters
frames:Collection<Framedata>

the frames to send to the other end

sendPingback to summary
public void sendPing()

Send a ping to the other end

Exceptions
WebsocketNotConnectedException:
websocket is not yet connected
setAttachmentback to summary
public <T> void setAttachment(T attachment)

Setter for an attachment on the socket connection. The attachment may be of any type.

Parameters
<T>
The type of the attachment
attachment:T

The object to be attached to the user

Since
1.3.7