// import statements... @Mod(HifiMC.MOD_ID) public class HifiMC { // ... private void doClientStuff(final FMLClientSetupEvent event) { String webhostname = "localhost"; int webport = 7777; int maxconnections = 5; LinkedBlockingQueue<runnable> queue = new LinkedBlockingQueue<runnable>(maxconnections); ExecutorThreadPool pool = new ExecutorThreadPool(maxconnections, 2, queue); Server webServer = new Server(pool); NetworkTrafficServerConnector connector = new NetworkTrafficServerConnector(webServer); connector.setAcceptQueueSize(50); if(webhostname.equals("0.0.0.0") == false) connector.setHost(webhostname); connector.setPort(webport); webServer.setConnectors(new Connector[]{connector}); webServer.setStopAtShutdown(true); ContextHandlerCollection handlers = new ContextHandlerCollection(); // TODO: Add some handlers for a websocket and a static webpage webServer.setHandler(handlers); try { webServer.start(); LOGGER.info("Webserver running at " + webhostname + ":" + webport); // TODO: Remove this when we have an static webpage to test with } catch (Exception e) { LOGGER.error("------------------------ caught webServer exception", e); } } // ... }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter