Networking A Game With More Than Two People?

free web hosting
Open Discussion > CONTRIBUTE > Computers > Programming Languages > Java, Java Servlets, Java Script, & JSP

Networking A Game With More Than Two People?

beeseven
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

 

 

 


Reply

uiop
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.

 

 

 


Reply

kl223
Hi!

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

These two concepts are the decentralized and centralized network plans. rolleyes.gif

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:


CODE
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? blink.gif

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

Reply

beeseven
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.

Reply

dazappa
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.

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.

Similar Topics

Keywords : networking


    Looking for networking, game, people

*RANDOM STUFF*





*SIMILAR VIDEOS*
Searching Video's for networking, game, people

*MORE FROM TRAP17.COM*
advertisement



Networking A Game With More Than Two People?



 

 

 

 

ADD REPLY / Got an Opinion! a humble request :-) RAPID SEARCH! Free Hosting [X]
Express your Opinions, Thoughts or Contribute your information that might help someone here.
Ask your Doubts & Queries to get answers.. "Together, We enlight each other!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE