org.java_websocket
Class WebSocketImpl

java.lang.Object
  extended by org.java_websocket.WebSocketImpl
All Implemented Interfaces:
WebSocket

public class WebSocketImpl
extends Object
implements WebSocket

Represents one end (client or server) of a single WebSocketImpl connection. Takes care of the "handshake" phase, then allows for easy sending of text frames, and receiving frames through an event-based model.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.java_websocket.WebSocket
WebSocket.READYSTATE, WebSocket.Role
 
Field Summary
 ByteChannel channel
          the possibly wrapped channel object whose selection is controlled by key
static boolean DEBUG
           
static List<Draft> defaultdraftlist
           
 BlockingQueue<ByteBuffer> inQueue
          Queue of buffers that need to be processed
 SelectionKey key
           
 BlockingQueue<ByteBuffer> outQueue
          Queue of buffers that need to be sent to the client.
static int RCVBUF
           
 WebSocketServer.WebSocketWorker workerThread
          Helper variable meant to store the thread which ( exclusively ) triggers this objects decode method.
 
Fields inherited from interface org.java_websocket.WebSocket
DEFAULT_PORT, DEFAULT_WSS_PORT
 
Constructor Summary
WebSocketImpl(WebSocketListener listener, Draft draft)
          crates a websocket with client role
WebSocketImpl(WebSocketListener listener, Draft draft, Socket socket)
          Deprecated. 
WebSocketImpl(WebSocketListener listener, List<Draft> drafts)
          crates a websocket with server role
WebSocketImpl(WebSocketListener listener, List<Draft> drafts, Socket socket)
          Deprecated. 
 
Method Summary
 void close()
          Convenience function which behaves like close(CloseFrame.NORMAL)
 void close(int code)
           
 void close(int code, String message)
          sends the closing handshake.
 void close(InvalidDataException e)
           
 void closeConnection()
           
protected  void closeConnection(int code, boolean remote)
           
 void closeConnection(int code, String message)
          This will close the connection immediately without a proper close handshake.
protected  void closeConnection(int code, String message, boolean remote)
           
 void decode(ByteBuffer socketBuffer)
           
 void eot()
           
protected  void flushAndClose(int code, String message, boolean remote)
           
 Draft getDraft()
           
 InetSocketAddress getLocalSocketAddress()
           
 WebSocket.READYSTATE getReadyState()
          Retrieve the WebSocket 'readyState'.
 InetSocketAddress getRemoteSocketAddress()
           
 boolean hasBufferedData()
           
 int hashCode()
           
 boolean isClosed()
          Returns whether the close handshake has been completed and the socket is closed.
 boolean isClosing()
           
 boolean isConnecting()
           
 boolean isFlushAndClose()
          Returns true when no further frames may be submitted
This happens before the socket connection is closed.
 boolean isOpen()
           
 void send(byte[] bytes)
           
 void send(ByteBuffer bytes)
          Send Binary data (plain bytes) to the other end.
 void send(String text)
          Send Text data to the other end.
 void sendFrame(Framedata framedata)
           
 void startHandshake(ClientHandshakeBuilder handshakedata)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

RCVBUF

public static int RCVBUF

DEBUG

public static boolean DEBUG

defaultdraftlist

public static final List<Draft> defaultdraftlist

key

public SelectionKey key

channel

public ByteChannel channel
the possibly wrapped channel object whose selection is controlled by key


outQueue

public final BlockingQueue<ByteBuffer> outQueue
Queue of buffers that need to be sent to the client.


inQueue

public final BlockingQueue<ByteBuffer> inQueue
Queue of buffers that need to be processed


workerThread

public volatile WebSocketServer.WebSocketWorker workerThread
Helper variable meant to store the thread which ( exclusively ) triggers this objects decode method.

Constructor Detail

WebSocketImpl

public WebSocketImpl(WebSocketListener listener,
                     List<Draft> drafts)
crates a websocket with server role


WebSocketImpl

public WebSocketImpl(WebSocketListener listener,
                     Draft draft)
crates a websocket with client role

Parameters:
socket - may be unbound

WebSocketImpl

@Deprecated
public WebSocketImpl(WebSocketListener listener,
                                Draft draft,
                                Socket socket)
Deprecated. 


WebSocketImpl

@Deprecated
public WebSocketImpl(WebSocketListener listener,
                                List<Draft> drafts,
                                Socket socket)
Deprecated. 

Method Detail

decode

public void decode(ByteBuffer socketBuffer)

close

public void close(int code,
                  String message)
Description copied from interface: WebSocket
sends the closing handshake. may be send in response to an other handshake.

Specified by:
close in interface WebSocket

closeConnection

protected void closeConnection(int code,
                               String message,
                               boolean remote)
Parameters:
remote - Indicates who "generated" code.
true means that this endpoint received the code from the other endpoint.
false means this endpoint decided to send the given code,
remote may also be true if this endpoint started the closing handshake since the other endpoint may not simply echo the code but close the connection the same time this endpoint does do but with an other code.

closeConnection

protected void closeConnection(int code,
                               boolean remote)

closeConnection

public void closeConnection()

closeConnection

public void closeConnection(int code,
                            String message)
Description copied from interface: WebSocket
This will close the connection immediately without a proper close handshake. The code and the message therefore won't be transfered over the wire also they will be forwarded to onClose/onWebsocketClose.

Specified by:
closeConnection in interface WebSocket

flushAndClose

protected void flushAndClose(int code,
                             String message,
                             boolean remote)

eot

public void eot()

close

public void close(int code)
Specified by:
close in interface WebSocket

close

public void close(InvalidDataException e)

send

public void send(String text)
          throws WebsocketNotConnectedException
Send Text data to the other end.

Specified by:
send in interface WebSocket
Throws:
IllegalArgumentException
NotYetConnectedException
WebsocketNotConnectedException

send

public void send(ByteBuffer bytes)
          throws IllegalArgumentException,
                 WebsocketNotConnectedException
Send Binary data (plain bytes) to the other end.

Specified by:
send in interface WebSocket
Throws:
IllegalArgumentException
NotYetConnectedException
WebsocketNotConnectedException

send

public void send(byte[] bytes)
          throws IllegalArgumentException,
                 WebsocketNotConnectedException
Specified by:
send in interface WebSocket
Throws:
IllegalArgumentException
WebsocketNotConnectedException

sendFrame

public void sendFrame(Framedata framedata)
Specified by:
sendFrame in interface WebSocket

hasBufferedData

public boolean hasBufferedData()
Specified by:
hasBufferedData in interface WebSocket

startHandshake

public void startHandshake(ClientHandshakeBuilder handshakedata)
                    throws InvalidHandshakeException
Throws:
InvalidHandshakeException

isConnecting

public boolean isConnecting()
Specified by:
isConnecting in interface WebSocket

isOpen

public boolean isOpen()
Specified by:
isOpen in interface WebSocket

isClosing

public boolean isClosing()
Specified by:
isClosing in interface WebSocket

isFlushAndClose

public boolean isFlushAndClose()
Description copied from interface: WebSocket
Returns true when no further frames may be submitted
This happens before the socket connection is closed.

Specified by:
isFlushAndClose in interface WebSocket

isClosed

public boolean isClosed()
Description copied from interface: WebSocket
Returns whether the close handshake has been completed and the socket is closed.

Specified by:
isClosed in interface WebSocket

getReadyState

public WebSocket.READYSTATE getReadyState()
Description copied from interface: WebSocket
Retrieve the WebSocket 'readyState'. This represents the state of the connection. It returns a numerical value, as per W3C WebSockets specs.

Specified by:
getReadyState in interface WebSocket
Returns:
Returns '0 = CONNECTING', '1 = OPEN', '2 = CLOSING' or '3 = CLOSED'

hashCode

public int hashCode()
Overrides:
hashCode in class Object

toString

public String toString()
Overrides:
toString in class Object

getRemoteSocketAddress

public InetSocketAddress getRemoteSocketAddress()
Specified by:
getRemoteSocketAddress in interface WebSocket

getLocalSocketAddress

public InetSocketAddress getLocalSocketAddress()
Specified by:
getLocalSocketAddress in interface WebSocket

getDraft

public Draft getDraft()
Specified by:
getDraft in interface WebSocket

close

public void close()
Description copied from interface: WebSocket
Convenience function which behaves like close(CloseFrame.NORMAL)

Specified by:
close in interface WebSocket


Copyright © 2013 Pusher. All Rights Reserved.