# WebSocket

This class represents a WebSocket server.

## private WebSocket()

Constructor for creating a new WebSocket server.

## public static WebSocket createServer()

Function for creating a new WebSocket server. Due to Android security restrictions,
the server must be created both in a separate thread and with a non-predefined port.
The port will be selected by the system.

## public void startListening()

Method for listening for incoming connections.
This creates a new thread for the server.

## public void stop()

Method for stopping the WebSocket server.

## public void setEventHandler(IWebSocketHandler handler)

Method for setting the event handler for this WebSocket server.
This event handler accepts all WebSocket events, such as:
- onConnected(Socket socket)
- onMessageReceived(WebSocket.Message message, WebSocket.MessageReply replier)
- onDisconnected(Socket socket)
- onError(Socket socket, String error)

## public ServerSocket getSocket()

Method for getting the ServerSocket connection.

## public boolean isConnected()

Method for checking whether this WebSocket connection is connected.

---

# WebSocket.Message

Class representing a message received from a WebSocket connection.

### Fields

- `WebSocketConnection connection`: The connection from which the message was received.
- `String message`: The message content.

## Opcode decode(byte opcode)

Method for decoding the opcode of a message.

## public Message(WebSocketConnection connection, String message)

Constructor for a WebSocket message.

# MessageReply

Interface for a message reply.
This can be used for sending back a response to the client, by calling
`reply(String message)`.