@Override
  public void run() {
    try {
      this.socket = new DatagramSocket(this.addr);
    } catch (SocketException e) {
      throw new RuntimeException(e);
    }

    while (true) {
      DatagramPacket request = new DatagramPacket(this.buf.array(), this.buf.capacity());
      try {
        socket.receive(request);
        ByteBuffer buf = ByteBuffer.wrap(request.getData(), 0, request.getLength());
        Messages msg = Messages.fromId(buf.getInt());
        byte[] data = new byte[buf.remaining()];
        buf.get(data);
        server.receive(msg, data);

      } catch (Exception e) {
        LOG.error("", e);
        if (this.socket != null) {
          this.socket.close();
          this.socket = null;
        }
      }
    }
  }