Package com.iizix.nio

Interface IWebSocketComm

All Known Implementing Classes:
InternalWebSocket, WebSocketClientEndPoint, WebSocketComm, WebSocketCommNIO

public interface IWebSocketComm
Interface to class that handles the WebSocket protocol.
Author:
Christopher Mindus
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    Checks if Binary Data Frames are supported.
    void
    Call this method to close the socket.
    boolean
    close(boolean rightNow)
    Call this method to close the socket.
    void
    close(int code, String reason)
    Call this method to close the socket.
    Gets the WebSocket attachment object, null for none.
    Gets the request domain.
    int
    Gets the port number for the connection to the server.
    Returns the Internet Protocol (IP) address of the client or last proxy that sent the request.
    Returns the fully qualified name of the client or the last proxy that sent the request.
    Returns the remote address to which this channel's socket is connected.
    Gets the state of the connection.
    Gets the negotiated and accepted sub-protocol, null for none (yet), or none is provided by the parties (server or client).
    boolean
    Checks if the connection is disposed of.
    boolean
    Checks if the connection is currently closing.
    boolean
    Flag for supporting software compression on client side.
    boolean
    Checks if the connection is established.
    boolean
    Checks if the connection is connecting.
    boolean
    Return if the connection is secured using SSL/TLS.
    void
    Opens the communication.
    void
    send(byte[] data)
    Sends binary data.
    void
    send(String data)
    Sends a String of data.
    boolean
    Sends a heart-beat.
    void
    setAttachment(Object attachment)
    Gets the WebSocket attachment object, null for none.
    void
    setSubProtocol(String subProtocol)
    Assigns a sub-protocol for the WebSocket (in case the processing of sub-protocol negotiation is done e.g.
  • Method Details

    • open

      void open() throws IOException
      Opens the communication.
      Throws:
      IOException
    • getState

      State getState()
      Gets the state of the connection.
      Returns:
      The state.
    • isConnecting

      boolean isConnecting()
      Checks if the connection is connecting.
      Returns:
      true if the connection is pending.
    • isConnected

      boolean isConnected()
      Checks if the connection is established.
      Returns:
      true if the connection is established.
    • isClosing

      boolean isClosing()
      Checks if the connection is currently closing.
      Returns:
      true if not closed, but closing.
    • isClosed

      boolean isClosed()
      Checks if the connection is disposed of.
      Returns:
      true if closed, not closing.
    • close

      void close()
      Call this method to close the socket.
    • close

      void close(int code, String reason)
      Call this method to close the socket.
      Parameters:
      code - A close code: zero for none, otherwise a code 1000 or range 4000 to 4999.
      reason - The reason code, can be null.
    • close

      boolean close(boolean rightNow)
      Call this method to close the socket.
      Parameters:
      rightNow - If true, the socket is hard-closed, i.e. no close conversation takes place with the server. If false, the client will send a close message to server that replies with a close itself, then the socket is closed.
      Returns:
      true if closed, false if already closed.
    • setSubProtocol

      void setSubProtocol(String subProtocol) throws IllegalStateException
      Assigns a sub-protocol for the WebSocket (in case the processing of sub-protocol negotiation is done e.g. outside the WebSocket communication acceptor).
      Throws:
      IllegalStateException - If the state doesn't permit this operation, or if the implementation doesn't allow it.
    • getSubProtocol

      String getSubProtocol()
      Gets the negotiated and accepted sub-protocol, null for none (yet), or none is provided by the parties (server or client).
      Returns:
      The String for the sub-protocol negotiated, null for none.
    • areBinaryDataFramesSupported

      boolean areBinaryDataFramesSupported()
      Checks if Binary Data Frames are supported.
      Returns:
      true if it is supported, false otherwise.
    • send

      void send(byte[] data) throws IOException
      Sends binary data.
      Parameters:
      data - The byte array containing the data.
      Throws:
      IOException - for failures, e.g. socket is closed, not open, not connected.
    • send

      void send(String data) throws IOException
      Sends a String of data.
      Parameters:
      data - The String to send.
      Throws:
      IOException - for failures, e.g. socket is closed, not open, not connected.
    • sendHeartBeat

      boolean sendHeartBeat() throws IOException
      Sends a heart-beat.
      Returns:
      true for success, false for failure (e.g. closing state or closed).
      Throws:
      IOException - For send failures.
    • getDomain

      String getDomain()
      Gets the request domain.
      Returns:
      The domain name of the server.
    • getPort

      int getPort()
      Gets the port number for the connection to the server.
      Returns:
      The port number.
    • isSecure

      boolean isSecure()
      Return if the connection is secured using SSL/TLS.
      Returns:
      The secure flag. Please note that if the server is behind a proxy, the connection might be secure anyway.
    • getRemoteAddr

      String getRemoteAddr()
      Returns the Internet Protocol (IP) address of the client or last proxy that sent the request. For HTTP servlets, same as the value of the CGI variable REMOTE_ADDR. The IP address format depends if it is an IPv4 or IPv6 address.
      Returns:
      a String containing the IP address of the client that sent the request.
    • getRemoteHost

      String getRemoteHost()
      Returns the fully qualified name of the client or the last proxy that sent the request. If the engine cannot or chooses not to resolve the hostname (to improve performance), this method returns the dotted-string form of the IP address (if IPv4, colon'ed-string for IPv6). For HTTP servlets, same as the value of the CGI variable REMOTE_HOST.
      Returns:
      a String containing the fully qualified name of the client.
    • getSocketAddress

      SocketAddress getSocketAddress()
      Returns the remote address to which this channel's socket is connected.

      Where the channel is bound and connected to an Internet Protocol socket address then the return value from this method is of type SocketAddress.

      Returns:
      The remote address; null if the channel's socket is not connected.
    • getAttachment

      Object getAttachment()
      Gets the WebSocket attachment object, null for none.
      Returns:
      An object set by setAttachment.
    • setAttachment

      void setAttachment(Object attachment)
      Gets the WebSocket attachment object, null for none.
      Parameters:
      attachment - The attachment object for the web socket.
    • isCompressionSupported

      boolean isCompressionSupported()
      Flag for supporting software compression on client side.
      Returns:
      The support flag depending on the subProtocol chosen.