use of com.b3dgs.lionengine.network.MessageType in project lionengine by b3dgs.
the class ClientUdp method taskReceive.
private void taskReceive() {
while (running) {
try {
final DatagramPacket packet = UtilNetwork.receive(socket);
final ByteBuffer buffer = UtilNetwork.getBuffer(packet);
final MessageType type = MessageType.from(buffer);
if (MessageType.DIRECT == type) {
channel.write(Direct.decode(buffer, clientId));
} else if (MessageType.DATA == type) {
channel.write(Data.decode(buffer, clientId));
} else if (MessageType.CLIENTS_LIST == type) {
handleClientsList(buffer);
} else if (MessageType.DISCONNECT == type) {
handleDisconnected(buffer);
} else if (MessageType.PING == type) {
handlePing(buffer);
}
} catch (final IOException exception) {
if (running) {
Verbose.exception(exception);
}
}
}
}
use of com.b3dgs.lionengine.network.MessageType in project lionengine by b3dgs.
the class ServerUdp method handleType.
private void handleType(DatagramPacket packet) throws IOException {
final ByteBuffer buffer = UtilNetwork.getBuffer(packet);
bandwidthDownSum.addAndGet(buffer.capacity());
final MessageType type = MessageType.from(buffer);
switch(type) {
case CONNECT:
connect(packet, buffer);
break;
case DISCONNECT:
disconnect(packet, buffer);
break;
case ALIVE:
alive(packet, buffer);
break;
case PING:
ping(packet, buffer);
break;
case DIRECT:
direct(packet, buffer);
break;
case DATA:
data(packet, buffer);
break;
case CLIENTS_LIST:
case UNKNOWN:
break;
default:
throw new LionEngineException(type);
}
}
Aggregations