Java NIO: a handshake, auth, lobby, gameRoom
in
Programming Questions
•
2 years ago
Hello everyone!
I have partly made a simple computer game and now I want to make it multiplayer ( I want to start multiplayering it while it is still in alpha, so there will be less problems later. The gameplay is already partly in place, so it is quite reasonable. ). Because the game is strategic and has a persistent world, I would like to make the network code based on NIO rather than on blocking sockets (so that it could hold many hundreds of clients and, as a side effect, I would gain a good knowledge of nio). I know there is a huge amount of work for me to do but it is ok because I know how to do everything except for NIO. The problem that I have is that I cannot figure out how to write the NIO code properly... All this NIO thing seems just alien in its logic to me (since I do not understand it YET).
To give an idea of what I want it to look like, here is a code of a server that I took as an example:
http://code.google.com/p/quantum-game/source/browse/?r=13#svn/trunk/src/main/java/quantum/net
It has the Login, Lobby and Game sections. However, it has no auth section and is written using the blocking sockets. So I have read MUCH about NIO and written my server and client as in all these similar "basic" NIO examples (just plain boring "hello"-"hello" thing). But still I can't understand how to create the separate handshake, authorization, lobby and game rooms? From what I understand, there should be ONE selector for the server, which should manage all connections? What keys and interest ops should be used and how?
Could please anyone describe, how to write a server that has all these facilities? Which way to go?
I have partly made a simple computer game and now I want to make it multiplayer ( I want to start multiplayering it while it is still in alpha, so there will be less problems later. The gameplay is already partly in place, so it is quite reasonable. ). Because the game is strategic and has a persistent world, I would like to make the network code based on NIO rather than on blocking sockets (so that it could hold many hundreds of clients and, as a side effect, I would gain a good knowledge of nio). I know there is a huge amount of work for me to do but it is ok because I know how to do everything except for NIO. The problem that I have is that I cannot figure out how to write the NIO code properly... All this NIO thing seems just alien in its logic to me (since I do not understand it YET).
To give an idea of what I want it to look like, here is a code of a server that I took as an example:
http://code.google.com/p/quantum-game/source/browse/?r=13#svn/trunk/src/main/java/quantum/net
It has the Login, Lobby and Game sections. However, it has no auth section and is written using the blocking sockets. So I have read MUCH about NIO and written my server and client as in all these similar "basic" NIO examples (just plain boring "hello"-"hello" thing). But still I can't understand how to create the separate handshake, authorization, lobby and game rooms? From what I understand, there should be ONE selector for the server, which should manage all connections? What keys and interest ops should be used and how?
Could please anyone describe, how to write a server that has all these facilities? Which way to go?
1