@Override
  public void connect() {
    if (socket == null) {
      socket = SocketIOImpl.create(this, host, port);
    }

    if (ConnectionState.CLOSED != getConnectionState()) {
      throw new IllegalStateException("Connection isn't closed!");
    }
    socket.connect();
  }
 @Override
 public void sendMessage(int messageType, String message) throws SocketIOException {
   if (ConnectionState.CONNECTED != getConnectionState()) {
     throw new IllegalStateException("Not connected");
   }
   socket.send(messageType, message);
 }
 @Override
 public ConnectionState getConnectionState() {
   ConnectionState state;
   if (socket != null) {
     state = ConnectionState.fromInt(socket.getSocketState());
   } else {
     state = ConnectionState.CLOSED;
   }
   return state;
 }
 @Override
 public void disconnect() {
   if (ConnectionState.CLOSED != getConnectionState()) {
     socket.disconnect();
   }
 }
 @Override
 public void close() {
   if (ConnectionState.CONNECTED == getConnectionState()) {
     socket.close();
   }
 }