Wednesday, April 4, 2007

Networking Part 2

Ahhh so I've been putting together a client and server GUI so I can test out my code, below is what I've got so far.

This is the client GUI I have been using to test the server. I can successfully connect to the server and use it to send a message to server, but I've been getting a lot of mixed results. When I send a message across to the server, it can end up printing it out more than one, and it doesn't return anything back to the client either. I am going to have to delve deeper into the code and look a little harder at just exactly what is going on between the server and client, I'll probably end up making a total mess of the code and put in a whole bunch of println and error messages everywhere so I can debug the thing, but hey, thats how I figure out how things work.

Moving on, I had a bit of a revolution about how everything works and just so I made sure I knew what was going on instantly started to put pen to paper and write down what I thought was going on. I really didn't trust myself to remember it if I came back to it later, but as I was writing it down it all seemed to make sense, this can only be a good thing. I tried to draw up a diagram to also better illustrate how it works but I think it needs more work, you can check it out below.

I don't know if its readable on this site (probably not) but what its trying to explain is that each computer, weather it be a player or the host, all have the server interface and three other modules that make it up (Input Handler, Server Connection Manager, Client Connection Manager). The naming of these modules might be a little bit off, but its the best I can come up with at the moment, below ill explain what each one does in a little more detail.

Input Handler - The input handler is designed to retrieve all the incoming packets from clients and redistribute that information back out to the other clients. It keeps a list of all the currently connected clients and stores their information about their connection so the server can communicate with the client. Eventually we would like to have it handle the events that occur during gameplay.

Server Connection Manager - This manager starts the server socket accepting incoming connections and for each connection made a new Input Handler is assigned to that client. The server socket will continue to accept new connections until either the game is started or the host disconnects.

Client Connection Manager - This manager is setup to detect incoming events or chat from the server and deal with it appropriately.

All of these classes run on their own thread, which means that the actual gameplay will be smooth and uninterrupted by the network.

No comments: