September 11, 20196 yr 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
September 11, 20196 yr Author 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.
November 28, 20196 yr This is actually a really nice release, I'll try and make a muling protocol over Thanksgiving break.
November 29, 20196 yr Author 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.
November 29, 20196 yr 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()); }
November 29, 20196 yr Author 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.
Create an account or sign in to comment