OOP network server advice

For everything that's not in any way related to PureBasic. General chat etc...
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

OOP network server advice

Post by Pantcho!! »

Hi all

As a student i am very busy with my studies, so no time for PB :(
Anyhow i have few intresting courses and one of them is Java Programming.

In our last project we need to create a client application and a server application.

The purpose of this project is to create a game server, where clients can conect and play against each other.

I am having issues about the programming of the server and i wanted advice from those who may experienced these issues before.

When a client connects the server he has the option to open a new room with some specifications for example max num players - until the room is not full the game will not begin OR join an existing room.

Thing is that each client that connects a thread is being launched.

my problem is to make communication with the threads to the ROOM itself.

I have two options in my mind:
- Lets say a client connects and creates a room.
A second client connects and wishes to join the room previously created by the client above.
I can assign the socketID of the client who wish to join the room to the ROOM properties (which will have now 2 sockets, the one who created the room and the on who joined) and kill the join user thread
since the thread of the user who created the room will handle them both.

in this option the thread of the user who created the room will manage all sockets but it is a problem since maybe the user who created the room can disconnect or there will be a slow down with other clients who are not responding and it will make the whole room lag.

- 2nd option is to leave each user on his own thread and assign them to ROOM where the room will communicate with each thread where if it needs to send data or receive data, here there is no dependency of the ROOM manager in the sockets, the threads manage them and if someone disconnect no matter who i don't have a problem.
But i just don't know if this is a good idea that the ROOM and sockets withh communicate through checks of boolean checks (of new input or output needed to be sended by the rooms) and buffer managing.

What do you guys think?

thanks.
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Post by citystate »

I'd lean towards option 3

have each player in their own thread, and each ROOM in its own thread too (with the stipulation that if the ROOM has an empty player list, the thread terminates)

each player has the following options:
  • create a new ROOM (and on creation, enters the ROOM)
  • enter an existing ROOM (leaving their current ROOM already)
  • leave their current ROOM (to the Lobby or disconnecting if already in the Lobby)
*shrug* that's my 2 bytes...
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
Post Reply