|
-
Mar 17th, 2009, 10:59 AM
#1
Thread Starter
Junior Member
Reading from a server?
Hello,
As you can see, first post =]. I've seen replies to questions and they seem to be good, solid answers so maybe i could get some help.
My situation...
I am working on a project in which the user can play another user on over the internet. Basically, how would i go about this?
What type of server would i need? Would i just use a designated computer as a server?
Also, what is the general process in contacting a server, reading/ writing from/to a server and storing data onto a server?
Regards.
-
Mar 17th, 2009, 11:47 AM
#2
Re: Reading from a server?
Welcome to VBForums.
The normal approach would be to have one of the players (lets call him/her Host A) host the game. This would mean that Host A would "be" the server in this session. The other player(s) (Host B and Host C) would then connect to Host A.
Host A would then have one connection to Host B and one connection to Host C. There would not be any connection between Host B and C in this scenario, so any data that needs to go from Host B to Host C or vice versa would have to go through Host A.
All this applies if you choose the connection oriented protocol TCP, if you choose UDP instead things would be a bit (a rather large bit infact!) different.
I would recommend you'd use TCP, unless you'd have any very specific reasons to use UDP.
TCP deals with communication between hosts as streams; Whatever you push into the stream on one side, will arrive in the same order on the other side. Think of it like some sort of magic pipe between the hosts.
About storing data on the server, that would depend entirely on what youre intending to store. You could use a database, simply write to a file, or only store data in variables on the running server application, which would of course reset the data whenever the server is restarted.
Was this roughly the answer you where looking for or where you looking for a more in-depth answer?
-
Mar 17th, 2009, 11:54 AM
#3
Thread Starter
Junior Member
Re: Reading from a server?
This is a great answer as of how to connect to eachother. There are only 2 people involved in one game (like chess for example). The only data that will be sent from one person to the other is the total score they get, then, if they win/ lose it will record it as a win on the server.
The server will contain usernames/ passwords/ username pin. It will also contain stats on each person(s). So i think i will need to use a database.
In each row of the database i could store username, password, pin, wins, losses, wins/ losses ratio etc, would the way to do this be using a database?
So im guess (if so) the database will be stored on an external server?
I guess im happy because i thought the server would route the scores to/ from eachother so now i know that the host is the client then its great because the activity of the server will be reduced.
So basically, is a database on a server the way forward?
Regards.
P.S. Thanks alot for your help on connections etc.
-
Mar 17th, 2009, 12:01 PM
#4
Re: Reading from a server?
Yeah, a database would be a good approach, and you would need a dedicated server to house this database.
-
Mar 17th, 2009, 12:08 PM
#5
Thread Starter
Junior Member
Re: Reading from a server?
Could i not just store it in an Excel document on the server and manipulate that? What are the advantages and disadvantages to this?
Regards.
-
Mar 17th, 2009, 12:09 PM
#6
Thread Starter
Junior Member
Re: Reading from a server?
Rather than buying a proper server could i just use a computer that is constantly on? Then IF i do need to turn it off for example i could save the data of the server somewhere as a backup?
Regards.
-
Mar 17th, 2009, 12:22 PM
#7
Re: Reading from a server?
 Originally Posted by Whack-A-Mole.NET
Could i not just store it in an Excel document on the server and manipulate that? What are the advantages and disadvantages to this?
Regards.
You could, but a database would offer more functionality, speed, and security.
 Originally Posted by Whack-A-Mole.NET
Rather than buying a proper server could i just use a computer that is constantly on? Then IF i do need to turn it off for example i could save the data of the server somewhere as a backup?
Regards.
Yes thats a very wise choice, dedicating a an old computer to running a server is often good enough. If you go for the database approach you wouldnt need to worry about taking backups when shutting the server down. You could however do occasional backups of the database itself in case an accident happens.
-
Mar 17th, 2009, 12:25 PM
#8
Thread Starter
Junior Member
Re: Reading from a server?
Brilliant thanks alot for your help.
What information would i need from the user in order to connect to the server?
For example, would i need the IP address of the user's computer etc? Please could you state what i would need to contact both the server and eachother.
Regards.
-
Mar 17th, 2009, 12:33 PM
#9
Thread Starter
Junior Member
Re: Reading from a server?
Also why would i not need to worry about backing it up if i turn the computer off? Surely the users cant read from/ write to the server if its off?
Regards.
-
Mar 17th, 2009, 12:45 PM
#10
Re: Reading from a server?
Backups are done so that you can restore data in case of data loss. No one will be able to communicate with the server when it is offline, I'm not entirely sure what you're saying.
Users wanting to connect to a host would have to know both the hosts IP and portnumber.
-
Mar 17th, 2009, 12:49 PM
#11
Thread Starter
Junior Member
Re: Reading from a server?
Ah OK i see.
So if a new user was registering i would need to know (basically):
Username
Password
PIN
IP Address
Port Number
Or is the Port Number established when the user wants to play the other play? For example, if person A wants to play person B, then would the port number be established? Or is the port number a constant? What i mean is the port number always the same for one computer? And also can i get the port number when person A wants to play person B?
Regards.
-
Mar 17th, 2009, 01:04 PM
#12
Re: Reading from a server?
It would depend on how you chose to code the game hosting. You as a developer decide what port the game host should use. It could be hardcoded, however this would mean that if any other application on the system is already using this local port, it wouldnt be possible to host the game. So I'd suggest letting the user decide what port the game should be hosted on.
The IP address and port number is information that will change alot. One suggestion I would like to make is:
When a user signs in on the "master server" as they're often referred as, you would update the IP Address field of that particular user in the database to the IP address used when signing in.
Dont store the port number in the table of users in the database, instead, when a user hosts a new game, it contacts the master server with details on this game...including its port number. The master server would store this information in a table of available games.
You'd then have all needed user information in one table and all information on hosted games in another table of the database.
When Person A wants to play Person B, he would just contact the master server and it can easily respond with both the IP address and port needed to connect to person B.
- End of suggestion -
-
Mar 17th, 2009, 01:24 PM
#13
Thread Starter
Junior Member
Re: Reading from a server?
Brilliant, so on registeration i would not need them to register the port number or the IP address as it would be better to obtain it when they choose to host/ join a game?
Regards.
-
Mar 17th, 2009, 01:25 PM
#14
Re: Reading from a server?
Exactly
-
Mar 17th, 2009, 01:34 PM
#15
Thread Starter
Junior Member
Re: Reading from a server?
Thank you so much for your help. Now i know what i have to head for in order to create an online environment. As of yet i don't know what kind of code i would need to contact the server (i.e. Sockets etc) but im sure i can work on that.
Once again, thank you.
-
Mar 17th, 2009, 10:21 PM
#16
Lively Member
Re: Reading from a server?
hmm your solution is a little scattered..
Write a Web Service
Have you client(s) talk to the web service
Web service talks to the Database...
use a n-tiered approach.
using a simple web service will allow you to communicate over http (web)... you wont need to worry about ports and ip addresses., your database will need to track who is playing what game..
if you want to go the advanced route., create a WCF., a wcf can talk over http., tcp., and a few other things., with a wcf you can also choose to implement a p2p style comm layer if you do decide to have 3+ users in a game... where everyone talks to everyone..
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|