Posted By:
aiyuen_sia
Posted On:
Sunday, June 30, 2002 06:57 PM
Hi! i'm creating a multiplayer client/server Checkers game. I'm actually using C# for it, but the concept of threading (which is the problem i'm facing) should be the same in Java as well. i have a class - MsgHandler(in the server side application) which handles all the incoming messages from the client. this class will parse the messages and call the other appropriate classes to process it. I have use the asynchronous I/O programming model in C# to handle multiple connections. That is fine. the problem is handling the multiple set of games being played by the players. i'm not sure how can i make it multithreaded. right now i have a class - GameController, which receieve any game messages from the MsgHandler, like 'join game', 'move'. i ha
More>>
Hi! i'm creating a multiplayer client/server Checkers game. I'm actually using C# for it, but the concept of threading (which is the problem i'm facing) should be the same in Java as well.
i have a class - MsgHandler(in the server side application) which handles all the incoming messages from the client. this class will parse the messages and call the other appropriate classes to process it. I have use the asynchronous I/O programming model in C# to handle multiple connections. That is fine.
the problem is handling the multiple set of games being played by the players. i'm not sure how can i make it multithreaded. right now i have a class - GameController, which receieve any game messages from the MsgHandler, like 'join game', 'move'. i have another class - GameTable, which is created everytime a new game is played. This class keeps track of the two players involved in that game. This means that there can be many GameTable object created. A hashtable is used in GameController, which keeps the GameTable object, with a table number as the key.
What is thought of doing is (which might be a problem later) to have GameController search the Hashtable whenever a game message is received using the table number. For example a message - 'GAMEMOVE|TableNumber1|PlayerName|23|32' where 23 and 32 is the source and destination of the piece that is moved. So GameController will search the Hashtable for the TableNumber1, gets the corresponding GameTable object, and send the move details to that object for validating the move before sending back a response to the players.
So my question is, where should i use threads? Should i create threads for each GameTable? i know i have to use threads somewhere, but i do not know where.
<<Less