To write an instant messenger program, I am trying to compose a simple server class that will run in its thread.
What should the server do
- accept connections from / connect to other server instances and bind selection keys for connections in
Map<Integer, SelectionKey> keys with an identifier so that the message flow can access the connections by identifier - read / write to connections
- keep incoming messages in the queue
- message flow can
- selection of incoming messages
- sent messages:
send_message(int id, String msg)
My current approach is mainly based on this example: A simple non-blocking echo server with Java nio .
I also used the Use of a selector to manage non-blocking sockets and real pages to learn about non-blocking sockets and selectors.
Current code
- EJP Offers Implemented
- minor changes
package snserver;
My question is: Is the above code correct and good, or what should I change? How to properly fulfill the requirements mentioned above? Also pay attention to my "TODO".
Thanks for the help!
source share