websocket4j.server
Class WebServerSocket

java.lang.Object
  extended by websocket4j.server.WebServerSocket

public class WebServerSocket
extends java.lang.Object

Server socket that accepts WebSockets.


Constructor Summary
WebServerSocket()
          Creates new WebServerSocket on random port.
WebServerSocket(java.lang.Integer port)
          Creates new WebServerSocket on given port.
 
Method Summary
 WebSocket accept()
          Accepts a new connection to the socket.
 void close()
          Closes the socket.
 java.lang.Integer getLocalPort()
          Returns local port to which this socket is bound.
 java.lang.Boolean isClosed()
          Checks if this socket is closed.
 void setSoTimeout(java.lang.Integer timeout)
          Sets maximum timeout for accept.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebServerSocket

public WebServerSocket()
                throws java.io.IOException
Creates new WebServerSocket on random port.

Throws:
java.io.IOException - thrown when there is an error while creating a new socket.

WebServerSocket

public WebServerSocket(java.lang.Integer port)
                throws java.io.IOException
Creates new WebServerSocket on given port.

Parameters:
port - port to use
Throws:
java.io.IOException - thrown when there is an error while creating a new socket.
Method Detail

setSoTimeout

public void setSoTimeout(java.lang.Integer timeout)
                  throws java.net.SocketException
Sets maximum timeout for accept.

Parameters:
timeout - maximum timeout for accept in milliseconds
Throws:
java.net.SocketException - thrown when there is an error while setting the timeout

getLocalPort

public java.lang.Integer getLocalPort()
Returns local port to which this socket is bound.

Returns:
local port

isClosed

public java.lang.Boolean isClosed()
Checks if this socket is closed.

Returns:
true if the socket is closed

close

public void close()
           throws java.io.IOException
Closes the socket.

Throws:
java.io.IOException - thrown when an error occurs while closing the socket

accept

public WebSocket accept()
                 throws java.io.IOException
Accepts a new connection to the socket.

Returns:
ready to use WebSocket that was accepted
Throws:
java.io.IOException - thrown when there is a problem with connection or protocol error