Link to home
Start Free TrialLog in
Avatar of turtletimer
turtletimer

asked on

Client/Server questions

I am making a multi-player card game.  I am going to have a server application.  The server is going to be able to handle multiple games as well.  I have a few questions.

I plan on making a GamePacket class with fields that will pertain to the game. This is the data that will be sent via ObjectOutputStream and recieved via the ObjectInputStream.  I am going to put a GameID field for the server to be able send the socket to the right Game thread.  Is this a good way to do this?  How is this usually done?

Should the client be constantly requesting updates for the game? Or should the game just send out game information?  I mean, once the intial connection is made I could  just get the IP address and have the client listening on a port.  But, I don't know if the clients firewall will block this.  How does this work?  

Overall, what is the best way to handle a multiplayer/multigame server application?
Avatar of Mayank S
Mayank S
Flag of India image

>> I plan on making a GamePacket class with fields that will pertain to the game. This is the data that will be sent via
>> ObjectOutputStream and recieved via the ObjectInputStream.

Sounds ok.

>> I am going to put a GameID field for the server to be able send the socket to the right Game thread.  Is this a good
>> way to do this?  How is this usually done?

There are many. This is one of them. Make sure the object is serializable. Some people often send data as XML strings, etc - that way, the client-side need not have the GamePacket class.

>> Should the client be constantly requesting updates for the game? Or should the game just send out game information?  

Depends upon what the game does. What kind of requests and updates are to be done? And what is the player at the client-side supposed to do in the game?

>> I mean, once the intial connection is made I could  just get the IP address and have the client listening on a port.

Don't make the client listen on a port. The server would already be listening to a port and the client would connect to that using the server's IP/ port. Then you should start off a new thread to service the client on that socket, and that socket should be used for communicating anything to the client using some predefined protocol.

>> But, I don't know if the clients firewall will block this.  

Read what I said above. Just make sure the server's fire-wall does not block it.
Avatar of turtletimer
turtletimer

ASKER

Okay, I was confused about that.  So, once a socket connection has been made, it stays made right?  I can keep calling the outputstream and inputstream of that socket?  And once the socket connection has been made the intial Server Application is going to ignore this incoming data?  This is where I get confused.  Let me explain my question better.  

1. A client requests to make a new game.  The server application answers this and ---
2. A new game is made on a seperate thread and the another thread within the game thread for the player i/o
3. Other players request to join this game and the server application routes them to the game thread where another thread is made for that player.
4. Now since there is a game thread and say 4 threads within in the game thread for each player, is there a continuous connection with each player(assuming the socket was passed to the thread)
5. Is the Server Application going to ignore all of this communication between the players and the game thread?

I just don't understand how the Server knows when to answer and when not too since all of this is going through the same port.  

Please explain well.  I've been searching around for days trying to understand this and it's just not clicking.  Links would be nice too. :)

P.S. This is a card game with four players.
ASKER CERTIFIED SOLUTION
Avatar of Mayank S
Mayank S
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial