dreameo Posted September 11, 2019 Share Posted September 11, 2019 Here's a very nice and easy to use Client/Server program. You must define you're own protocol and modify the onMessage functions to then support your protocol. MessageParser.java and Message.java must be altered to reflect your protocol (such that you can extract the required data). Note: Not fully tested, could be some problems. Let me know. https://gist.github.com/DreamLean/61b215bad3c8f839ac4c84536d67c804 5 1 Quote Link to comment Share on other sites More sharing options...
tarxan Posted September 11, 2019 Share Posted September 11, 2019 Nice release Quote Link to comment Share on other sites More sharing options...
dreameo Posted September 11, 2019 Author Share Posted September 11, 2019 Interesting to see if anyone can create a nice protocol. Word of advice, the client should be the driver for the protocol. The server is the central place where information is held and decisions are returned to the client should they ask for direction. 1 Quote Link to comment Share on other sites More sharing options...
agentcallooh Posted November 28, 2019 Share Posted November 28, 2019 This is actually a really nice release, I'll try and make a muling protocol over Thanksgiving break. Quote Link to comment Share on other sites More sharing options...
dreameo Posted November 29, 2019 Author Share Posted November 29, 2019 22 hours ago, agentcallooh said: This is actually a really nice release, I'll try and make a muling protocol over Thanksgiving break. You'd be the first. Quote Link to comment Share on other sites More sharing options...
agentcallooh Posted November 29, 2019 Share Posted November 29, 2019 Update, been playing with this a bit more. Still working on a protocol, but in working with it I did find at least one issue. Should the server close immediately or not gracefully, this error will be repeatedly thrown from Client.onMessage as it is called regularly by the ScheduledExecutorService. I found a somewhat-OK fix through a StackOverflow answer. I pulled out the ByteBuffer operations and did a test of the exception message, which is quite messy but works. private void onMessage() { ByteBuffer inputBuffer = ByteBuffer.allocate(256); try { client.read(inputBuffer); } catch (IOException e) { // If the server was closed, the IOException will hint at this. // https://stackoverflow.com/questions/5638231 if (e.getMessage().contains("An existing connection was forcibly closed by the remote host")) { System.out.println("Server closed, stopping."); close(); return; } e.printStackTrace(); } consumer.accept(new String(inputBuffer.array()).trim()); } Quote Link to comment Share on other sites More sharing options...
dreameo Posted November 29, 2019 Author Share Posted November 29, 2019 I would suggest having the server send to every client and tell the client to shutdown. The server shouldn't be closing for any reason (especially prior to any client closing). It's the central place to where all communication happens. Quote Link to comment Share on other sites More sharing options...