we then add that socket as a handler

PHOTO EMBED

Fri Feb 26 2021 19:54:11 GMT+0000 (Coordinated Universal Time)

Saved by @surrealemily

@Mod(HifiMC.MOD_ID)
public class HifiMC {
    // ...

    // Convenience method to create and configure a ContextHandler.
    private static ContextHandler createContextHandler(String contextPath, Handler wrappedHandler) {
        ContextHandler ch = new ContextHandler (contextPath);
        ch.setHandler(wrappedHandler);
        ch.clearAliasChecks();
        ch.setAllowNullPathInfo(true);
        return ch;
    }

    // ...

    private void doClientStuff(final FMLClientSetupEvent event) {
        // Server webServer = ...

        ContextHandlerCollection handlers = new ContextHandlerCollection();

        WebSocketHandler wsh = new WebSocketHandler.Simple (LocationDataWebSocket.class);
        handlers.addHandler(createContextHandler("/locdata", wsh));

        // TODO: Add a handler for a static webpage

        webServer.setHandler(handlers);

        // webServer.start() ...
    }

    // ...
}
content_copyCOPY