use of io.anuke.mindustry.net.Packets.Connect in project Mindustry by Anuken.
the class WebsocketClient method connect.
@Override
public void connect(String ip, int port) {
socket = new Websocket("ws://" + ip + ":" + webPort);
socket.addListener(new WebsocketListener() {
public void onMessage(byte[] bytes) {
try {
ByteBuffer buffer = ByteBuffer.wrap(bytes);
byte id = buffer.get();
if (id != -2) {
// ignore framework messages
Class<?> type = Registrator.getByID(id);
Packet packet = (Packet) ClassReflection.newInstance(type);
packet.read(buffer);
Net.handleClientReceived(packet);
}
} catch (ReflectionException e) {
throw new RuntimeException(e);
}
}
@Override
public void onClose() {
Disconnect disconnect = new Disconnect();
Net.handleClientReceived(disconnect);
}
@Override
public void onMessage(String msg) {
onMessage(Base64Coder.decode(msg));
}
@Override
public void onOpen() {
Connect connect = new Connect();
Net.handleClientReceived(connect);
}
});
socket.open();
}
Aggregations