I’m currently writing server software for a game that has chatrooms, and allows users to start games from within the server. I need a book that explains how to transmit data from computer to computer. I’m currently looking at the O’Reilly book entitled “Java Network Programming.” Any advice?
If you feel confident enough to skip past begginer books then the author to Java NIO has been helpful when I emailed him so I feel compelled to plug his book. Also, for a very large number of connections NIO is the only way to go.
If I was writting a chat feature I’d base the protcol on what is known of the AIM protocol. It’s been proven to be a solid and flexiable design and I’m kind fond of the design myself.
As for code, you’d need to keep a java.util.Set of all logged in users to allow user to user messages. Then you’d need a Set for all rooms and each room would need to keep a Set of the users in that room so that messages to a room can be broadcast to each user.
HTH
[quote]If you feel confident enough to skip past begginer books then the author to Java NIO has been helpful when I emailed him so I feel compelled to plug his book. Also, for a very large number of connections NIO is the only way to go.
[/quote]
What do you think of the book? Personally, I’m interested in the “multiplexing NIO” chapter - how advanced it is, what topics it covers, etc. All existing resources are too basic (as noted in the thread on NIO which we’ve both been quite active in ;D).
[quote]I’m interested in the “multiplexing NIO” chapter - how advanced it is, what topics it covers, etc.
[/quote]
That chapeter is available online: http://www.oreilly.com/catalog/javanio/
Here is a quote that is relevent to our other long thread but I’m not gonna make another post just for it. From page 144 of the Java NIO book:
[quote]For the first scenario, in which you want to bring more threads into play to service channels,resist the urge to use multiple selectors.Performing readiness selection on large numbers of channels is not expensive;most of the work is done by the underlying operating system. Maintaining multiple selectors and randomly assigning channels to one of them is not a satisfactory solution to this problem.It simply makes smaller versions of the same scenario.
A better approach is to use one selector for all selectable channels and delegate the servicing of ready channels to other threads.You have a single point to monitor channel readiness and a decoupled pool of worker threads to handle the incoming data. The thread pool size can be tuned (or tune itself,dynamically)according to deployment conditions. Management of selectable channels remains simple,and simple is good.
[/quote]
Thanks. Yeah, I’d love to use just one selector, but the claim that it’s easier this way is rubbish. You have a load of extra complexity if you don’t at least split into different selectors for different interest sets; c.f. the SEDA resource - it really is a lot easier to program that way. I’m reasonably confident that minor changes in the nio API’s could change things so that the book’s claim was more accurate. Once nio works properly (still some major bugs on a few platforms), perhaps Sun will make moves to make it a bit easier to use - at the moment, ASSUMING the bugs were fixed, it’s a bit like pointers: very powerful, hard to understand until you’ve used it a lot, and easy to make mistakes that are very hard to debug.
PS I’m still hoping to look at your code from that other thread in a lot more detail, but still too overworked for the time being