I'm working with an implementation of MINA that uses a NioAccepter.
My task is to make a basic java.net.Socket
framework interface with both other java.net.Socket
frameworks as well as Apache's MINA NIO framework.
This should have been simple enough, passing the raw socket from the MINA to my framework.
However, I开发者_如何学运维've yet to succeed in exposing the raw socket. This is the first time I've looked at the MINA framework and I'm pretty confused.
The closest I got to a result was this:
((SocketChannel)((NioSession)sess).channel).socket()
Which would have solved my problems, except NioSession.channel
is protected.
Am I missing something here?
Not many frameworks give you access to the underlying socket. It's only really safe to be used by one thread when other threads aren't locking it. Here, MINA is using encapsulation to lock it away, and they're using an asynchronous selector model, so you shouldn't touch the socket at all or you'll mess it up.
Anyway, a better idea if you really want to use multiple socket frameworks is to just use different ports. Really, though, just stick with one. And I'd advise KryoNet which does much the same thing but in far, far fewer lines of code, if you want to get down and dirty with something you can modify and is easy to understand. I've already modded the hell out of my version of KryoNet.
精彩评论