Search code examples
scalanio

Socket manager for client sockets using nio


I am a newbie Scala developer trying to figure out how to design a socket manager using Java nio.

I would like the manager to handle messages such as 'connect', 'disconnect' and 'send' etc and be able to manage several client sockets by sending them 'onData' messages with received data.

To my understanding, the selector has to run in a thread of its own.

So I can put the selector selecting in its own thread, but how can I register new socket channels with the selector (to my understanding a selector is not thread safe) while the selector may be in a call to select?

What is a good design when combining actors and threads in Scala?


Solution

  • Unless you're doing this for purely didactic purposes, my advice is "Don't reinvent the wheel." :)

    Actors + NIO = Naggati.

    Or, if you want something lower-level, I'd suggest Netty (which Naggati uses)