Search code examples
javaniogrizzly

Telnet to the EchoServer Grizzly sample application


I've been working on a server application that will over time receive quite a lot of connections. In order to be able to handle this I have been implementing a non blocking design using the standard java NIO classes. But there are a lot of details to handle, and I would much prefer to use some sort of framework. Preferably I would like to use Spring Integration but I have not been able to find some simple, working examples.

In stead I am now evaluating the Grizzly framework, which seems to offer the functionality I need. I implemented their EchoServer example but found that I was unable to Telnet to the server and have the results echoed back to me on the console. Their EchoClient application works as expected.

In my case I cannot make any assumptions about the clients trying to connect to me, so I have to be able to support everything from simple telnet clients to NIO clients. Is Grizzly able to do this, and if so how?


Solution

  • The sample you're working with is based on special input format implemented by StringFilter. The StringFilter decodes/encodes Strings as sequence of bytes with a string-length prefix. For sure telnet doesn't use the same format to encode Strings that's why server doesn't echo the data back. In order to make the server work with telnet - just remove a StringFilter from the server's FilterChain (comment out this line):

    //          filterChainBuilder.add(new StringFilter(Charset.forName("UTF-8")));