Jump to content
  • Advertisement
Fast Arrows

Education Where to learn how to set up and use game server for my game?

Recommended Posts

So im starting to build game for me and my friend to play but if it ends up good then i want it to be easily expandable. My question is ... Where do i learn how to set up a server? how to run code on my server? how do you open your server to the outside world. Not only your home/pc. I want to program my server in java because i'm fairly comfortable with java. I've decided i want a tcp server. Do i need separate server to handle log-ins, registers etc.? I've done a lot of googling and i still can't find any decent tutorials.

Edited by Fast Arrows

Share this post

Link to post
Share on other sites

The reason there aren't any "decent tutorials" is that this is a very big topic. The specific solutions you end up with depend a lot on the needs of your game.

To start a server, bind() your socket to a port, and listen()/accept() connections on that port.

To open that server up to the internet, make sure any firewall you have is set to forward incoming traffic on your port to the machine running the server, and make sure there's a domain name pointing at the address your external firewall is assigned.

If you want to support "server chooser" type features, such as game lobby, or world shard/instance, then you need to separate "login" from "connect to game." However, if there's just one single game instance that everyone plays in at the same time, you don't need to separate login server from game server. However, once you have more than a hundred or a few hundred players in a single level/world, you're going to need to start breaking up game serving on many machines, which may mean many different servers (from the point of view of the external world seeing an IP address and port) or not -- again, depending on what makes sense for your game and infrastructure.


Share this post

Link to post
Share on other sites

When it comes to network programing, it's more in the 'enterprise application' area than game programing I guess. Have you checked out some article like "Network Programming in Java" ? There are books that covers this area as well. 

Regardless, since you're using TCP with Java, I think you should start with ServerSocket. Create an instance of ServerSocket in your server code, call `accept()` method. The program will wait until a client connects to the server, and the method will return a Socket instance when a client is connected. On the client side, use Socket to connect to the server. When there's a connection, each end will has its own socket instance. Use this instance to send data to the other end. 

That's a gist of a super basic TCP client-server application. It's not enough to do grand things like serving games, but that should be a good begining. 

18 hours ago, Fast Arrows said:

Where do i learn how to set up a server?

If you mean the machine, basically it is just a computer. Dedicated server has special OS like Windows Server or RHEL on it, and use server-grade equipment. For the beginer you don't have to go that far. You can also use some cloud server/vm hosting like Digital Ocean so you don't have to look after the machine. 

In fact you might not even need your own server. You can just deploy your code on the cloud services like Google Cloud, MS Azure, or Amazon Web Services.

18 hours ago, Fast Arrows said:

how to run code on my server?

Since a server is just a computer, you just run your program like... another program. 

For more complex setup, there are ways to deploy the code and run on the server. If I'm not mistaken, LOL/ROV team run their services in docker containers... I think you don't have to go this far... yet.

18 hours ago, Fast Arrows said:

how do you open your server to the outside world.

If the server connects to an internet directly, then it can be accessed from the outside using the server's IP. If is behind some kind of NAT (network address translation) or firewall, then it can't be accessed from the outside. 

You can use cloud server like DO (as mentioned previously) to host the server code. The sever will be accessible from the public. Cloud services like GCP, Azure, or AWS are of course accessible from the public as well.

After the server is accessible from the public, you can also assigned a domain name to the IP address the server is assigned. This way the server can be referred to by a domain name rather than an IP address.

18 hours ago, Fast Arrows said:

Do i need separate server to handle log-ins, registers etc.?

You don't have to. Personally I'd use multiple services to handle different kind of message. These service can run on the same server. Later when one server can't handle all the load required, then I can fire up more servers and deploy some of the servces to them.

I probably don't want to go too far like Mirco Service Architecture though. Handling a few hundreds kind of service sounds like a headache to me. 

Anyway for starter, having only one service is more than enough. In fact I'd suggested to start with a very very small project like 2 players tic-tac-toe or rock-paper-scissor. 

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!