Jump to content
xisto Community
Sign in to follow this  
beeseven

Networking A Game With More Than Two People?

Recommended Posts

In Java, it's pretty easy to set up a connection between two people, but I've been thinking about how best to connect more than two. If you only have a small number of people, and you know about what that number will be beforehand, you could have a direct connection from every person to every other person. However, if you have a lot of people or you don't know how many there will be, it's kind of difficult. Here are some things I've thought of, comments/suggestions/ideas would be appreciated:

Have each person store a list of connections and iterate over the list when you need to send/receive data.

Pros: Easier to implement

Cons: Might eat up bandwidth if the clients don't have much


Have each person only have a connection to the server which stores connections to everyone. When the server receives data from one connection, send it to all the others.

Pros: If the server has a lot of bandwidth, it wouldn't put strain on the clients

Cons: Harder to implement, lots of threads needed if connections don't send data in any order



Share this post


Link to post
Share on other sites

I don't know much about Java programming but both of those sound like good ideas. I am a proficient Visual Basic programmer and know about computer structure however so maybe I can help a bit.I think that you should either go with the first one or do a modified "BitTorent approach". Why not set it up so that there is a central server that anyone wishing to play the game connects to. That server then winsocks them a list of IPs playing the game. If you spent enough time on it I'm sure that you could fiqure out a way so that all the computers communicated with each other, but have some communicate with more than one depending on the machine's bandwidth.I'm not sure if this would work but you could also try working in a "ring". You could try grouping the computers in say groups of five. Then designate a "lead" computer that serves the data to the group and fetchs it from a central server.I hope that my ideas help and that you figure it out! PM me with how you decide to do it and the results, I'd like to make a online game as well.

Share this post


Link to post
Share on other sites

Hi!

At first, sorry for my english. :D I'm doing my best to show you some things.

These two concepts are the decentralized and centralized network plans. :)

I've implemented server/client applications with both concepts, and I can say the decentralized one is more difficult.
On google you can find some text to read under the keyword: "graph theory".

At first, with it, every client needs an opened port. Only then are other clients able to connect.
Then, it's truly hard to develop the network so that every client gets every line of data. Think of it: there is basically a graph: the network of the connected clients. (The nodes are the clients themselves, of course and the lines are the connections beetween them.) How can you find a path for the information that arrives by every client AND avoids circuits.

Of course it is not possible to connect every client to every other clients. It would mean too many connections. And also would mean lotsa slow clients.

Besides, it eats up much more bandwith, because you (as a client) might need to forward someone else's data, too. (in case you don't connect to every other clients) Look at that graph:


A -- +	+-----D	   \  /		C	   /  \B -- +   + -----E

Here are there 5 clients. They connect through the C client. In other words, C is the gateway. All the data A, B, D and E are sending to each other is going through C.
Would you like to be the C client? :)

And there are more such problems you have to think of. It can more easliy be done with small networks. That's why I think the most powerful solution is like with Direct Connect or IRC.
There are servers which can be connected to each other in a quite small network. (not 1000000 users connect to each other, just 10-15 servers)

Summa summarum: such a network shouldn't be developed without the needed knowledge.

The second plan sounds more valuable.
I suggest you should use async sockets for the server, so you don't have to use many threads in the server. Basically, the socket sends a signal when it has incoming data, you don't have to check it explicitly. You can take a look at it in the java.nio package.

kl223
Edited by kl223 (see edit history)

Share this post


Link to post
Share on other sites

What I would be using this for immediately is just a game, so it would be fine if each client sent to everyone and then received from everyone. I tried to make a chat but there were too many Threads and it got confusing. I thought about having a separate server program but realized that I don't really have a reliable server that could do that. For now, unless I have a stroke of genius, my game will remain two-player only, but I'll check out java.nio.

Share this post


Link to post
Share on other sites

First of all make a multi-threaded server. Then for each connecting player throw a new thread. Also you can make the client send "codes" to the server when an action is done. Like if keyboard left is pressed send code 1, then server sends code 1 to all of the clients to update the game. That way the client is doing all the figuring and saves badwidth.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.