Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Networking and threading question

Status
Not open for further replies.

luvcloud

Programmer
Apr 23, 2002
24
MY
Here's the scenario.
I'm developing this networking boardgame that can support multiplayers. Right now, in order to communication between the server and client, I have predefined commands (or communication protocol) that the server and the client can understand. For example, if a new player gets connected, the client appends 'Conn' before the msg sent to the server, or if a player sends a chat msg, the client appends 'Chat' before the msg. All this is controlled by a method in the MainServerControl class called ProcessClientCmd. It has a series of switch statements for each predefined commands.

Here's the problem area:
I have another class GameObject which keeps track of each set of games being played. It keeps track of the two players involved in the game and also the other players who are 'watching' this particular set of game. The logic of the boardgame is also contained in this class. I'm looking for a more effective way of communication between players in particular set of game.

Currently what i plan to do is, in the MainServerControl, i have kept an arraylist of GameObject instances. Whenever a player makes a move, the msg from the client (containing the move that player made) will first go through ProcessClientCmd. From here it will go through the arraylist of GameObject and search of the particular game set this player is involved in. Once found it verifies the move. And then it echos the move to the other players involved in that set of game. So in short, arraylist is used to control each game set.

Would that be an effective way of doing things? I'm not sure if any threading problems will come up or not too. Can anyone give me some ideas on how to go about it? The players' turn to move is also not controlled by the server. Instead i have put a variable - myMove of type boolean which is set to true everytime the opponent makes a move (that is everytime the clientApp receives the opponent's move echoed by the server) and set to false after his move. Is that correct?
 
Are the players who can update the board on the same thread?

If not, you'll have the classic "multiple-writers" problem, where depending on the timing involved, one player can make a move at the same time as another player, and the first one in wins (the second player has just made a move based on stale information).

The players who are "lurking" can be run on another thread, and if they get old info, that's too bad, but it won't affect the outcome of the game.

Chip H.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top