Java puzzle (Single threaded client server)
Join the DZone community and get the full member experience.Join For Free
Without creating additional threads, create a ServerSocket on a random unused port, a client Socket connecting to localhost and a server Socket.
Part 1) Send messages from client to server and back again. (This can be useful in unit tests)
Part 2) Do the same with blocking NIO.
Part 3) Benchmark how many GB/s per second you can transfer this way.
Part 4) Measure the typical and 99.99% round trip latency, and estimate how much garbage is produced.
For bonus points try the same with Async NIO2 in Java 7.
Opinions expressed by DZone contributors are their own.