UDPServer/src/com/eh7n/f1telemetry/F1_output.java
/**
     * Start the F1 2018 Telemetry UDP server
     *
     * @throws IOException           if the server fails to start
     * @throws IllegalStateException if you do not define how the packets should be
     *                               consumed
     */
Start the F1 2018 Telemetry UDP server
@throws IOException           if the server fails to start
@throws IllegalStateException if you do not define how the packets should be
consumed
Start the F1 2018 Telemetry UDP server @throws IOException if the server fails to start @throws IllegalStateException if you do not define how the packets should be consumed
public void start() throws IOException {
        if (packetConsumer == null) {
            throw new IllegalStateException("You must define how the packets will be consumed.");
        }
        log.info("F1 2018 - Telemetry UDP Server");
        ExecutorService executor = Executors.newSingleThreadExecutor();
        try (DatagramChannel channel = DatagramChannel.open()) {
            channel.socket().bind(new InetSocketAddress(bindAddress, port));
            log.info("Listening on " + bindAddress + ":" + port + "...");
            ByteBuffer buf = ByteBuffer.allocate(MAX_PACKET_SIZE);
            buf.order(ByteOrder.LITTLE_ENDIAN);
            while (true) {
                channel.receive(buf);
                final Packet packet = PacketDeserializer.read(buf.array());
                executor.submit(() -> {
                    packetConsumer.accept(packet);
                });
                buf.clear();
            }
        } finally {
            executor.shutdown();
        }
    }
public void start ( ) throws IOException { if ( packetConsumer == null ) { throw new IllegalStateException ( "You must define how the packets will be consumed." ) ; } log . info ( "F1 2018 - Telemetry UDP Server" ) ; ExecutorService executor = Executors . newSingleThreadExecutor ( ) ; try ( DatagramChannel channel = DatagramChannel . open ( ) ) { channel . socket ( ) . bind ( new InetSocketAddress ( bindAddress , port ) ) ; log . info ( "Listening on " + bindAddress + ":" + port + "..." ) ; ByteBuffer buf = ByteBuffer . allocate ( MAX_PACKET_SIZE ) ; buf . order ( ByteOrder . LITTLE_ENDIAN ) ; while ( true ) { channel . receive ( buf ) ; final Packet packet = PacketDeserializer . read ( buf . array ( ) ) ; executor . submit ( ( ) -> { packetConsumer . accept ( packet ) ; } ) ; buf . clear ( ) ; } } finally { executor . shutdown ( ) ; } }
Start the F1 2018 Telemetry UDP server
 @throws IOException           if the server fails to start
 @throws IllegalStateException if you do not define how the packets should be
                               consumed
Start the F1 2018 Telemetry UDP server @throws IOException if the server fails to start @throws IllegalStateException if you do not define how the packets should be consumed
// Create an executor to process the Packets in a separate thread // To be honest, this is probably an over-optimization due to the use of NIO, // but it was done to provide a simple way of providing back pressure on the // incoming UDP packet handling to allow for long-running processing of the // Packet object, if required. //in a separate thread // the print format is //17:14:43.249 [pool-1-thread-1] TRACE c.e.f.F12018TelemetryUDPServer - {"header":{"packetFormat":2018,"packetVersion":1,"packetId":2,"sessionUID":17024013698017524279,"sessionTime":164.88759,"frameIdentifier":7462,"playerCarIndex":0}," //begin to print