websocket4j
Class AbstractWebSocket

java.lang.Object
  extended by websocket4j.AbstractWebSocket
Direct Known Subclasses:
WebSocket, WebSocket

public abstract class AbstractWebSocket
extends java.lang.Object

This class implements common functionality of server and client side web socket.


Constructor Summary
AbstractWebSocket(java.net.Socket socket, java.lang.Integer timeout, java.lang.Object... args)
          Creates new WebSocket instance using given socket for communication and limiting handshake time to given milliseconds.
 
Method Summary
 void close()
          Closes the connection.
 java.lang.String getMessage()
          Gets a message form the other party.
 boolean isClosed()
          Checks if this socket is closed.
 void sendMessage(java.lang.String message)
          Sends a message to the other party.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractWebSocket

public AbstractWebSocket(java.net.Socket socket,
                         java.lang.Integer timeout,
                         java.lang.Object... args)
                  throws java.io.IOException
Creates new WebSocket instance using given socket for communication and limiting handshake time to given milliseconds.

Parameters:
socket - socket that should be used for communication
timeout - maximum time in milliseconds for the handshake
Throws:
java.io.IOException - exception thrown when there is communication error or protocol error
Method Detail

close

public void close()
           throws java.io.IOException
Closes the connection. Close is brutal, without the closing handshake. It worked better in some web browsers, but it might change sometime.

Throws:
java.io.IOException

getMessage

public java.lang.String getMessage()
                            throws java.io.IOException
Gets a message form the other party. Blocks if nothing is available.

Returns:
message from the other party
Throws:
java.io.IOException - thrown when there is a problem with the connection or protocol

isClosed

public boolean isClosed()
Checks if this socket is closed.

Returns:
true if the socket is closed

sendMessage

public void sendMessage(java.lang.String message)
                 throws java.io.IOException
Sends a message to the other party.

Parameters:
message - message to be sent
Throws:
java.io.IOException - thrown when there is a problem with the connection.