Could I use a raspberry pi as a server for a mobile game.

Started by
13 comments, last by alnite 6 years, 6 months ago

So starting a new mobile game and this time I want to add a proper leader board and allow players to retrieve profiles. For my first game I used Facebook to hold score, however the one score per player limit and the fact that you can only see the score of friends are annoying.

So now I wan my own server to deal with it except servers are expensive and I only need to store int and a copy of the Unity save.I have been thinking about getting my self a raspberry pi and turning it into a server for the mobile game, then I could also use it for my other mobile games if I want.

1.) Can I even use a raspberry pi as a server?

if I can

2.) How hard would it be and how long would it take more or less? (Assume I know nothing of networking.)

3.)What kind of maintenance am I looking at? I notice the rasberry doesn't have a cover or anything. It would have to run day in and out.

if I can't

4.) What are my other options?

I notice free server sites often forbid game hosting and only data storage, I think because then no one sees the adverts these sites use.

I really don't need much. Based on my projections from my other mobile games I think I am going to get around 500 - 800 players for about a month before it rapidly drops down. So I only need to store around 2000 player's data. Having my own server would make it easy to create more complex mobile games as I advance.

 

I am doing this for the experience so I don't mind if it's difficult or comes with some expense, I just don't want to spend thousands on this.

Advertisement

The pi works as a great server for personal use, depending on what exactly you need it for. but if your expecting large volumes of people to play your game, the pi will most definitely not cut it. You could certainly start out with it though, and upgrade later. I have a couple pi's set up as servers at my house, ones even hosting a site (not a public site though)

24 minutes ago, iedoc said:

but if your expecting large volumes of people to play your game, the pi will most definitely not cut it.

Lucky I am not expecting much. I think that it's going to take a long while before my games get decent downloads.

Thanks for letting me know it's possible.

3 hours ago, Scouting Ninja said:

1.) Can I even use a raspberry pi as a server?

You can turn any computer to a server.

 

3 hours ago, Scouting Ninja said:

2.) How hard would it be and how long would it take more or less? (Assume I know nothing of networking.)

3.)What kind of maintenance am I looking at? I notice the rasberry doesn't have a cover or anything. It would have to run day in and out.

Hosting your own server (raspberry pi or not) involves dealing with making sure people from outside can access that box sitting under your desk. You'd most likely need to open up a port on your router. Some say it was that easy, but some others have said that they also need to call their cable provider to let incoming traffic into their home router. YMMV.

There exists tools like ngrok to let you tunnel in without having to deal with all above, but they may have certain limitations on the free version.

Maintaining a home server is not just making sure it has a cover. It is to also make sure it keeps on running, and your server app is not crashing under any condition. Power outages, network loss, DDoS are some of the things that you need to worry about.

1 hour ago, alnite said:

Maintaining a home server is not just making sure it has a cover. It is to also make sure it keeps on running, and your server app is not crashing under any condition. Power outages, network loss, DDoS are some of the things that you need to worry about.

Thank you for this, it's exactly the kind of information I need. In the past I hired a server and of course these things are easy to miss when other take care of them.

1 hour ago, alnite said:

You'd most likely need to open up a port on your router. Some say it was that easy, but some others have said that they also need to call their cable provider to let incoming traffic into their home router. YMMV.

Good to know. I remembered that I had problems with incoming traffic when I set up my render farm, so chances are I will need to look into this.

1 hour ago, alnite said:

You can turn any computer to a server.

I wasn't 100% sure the raspberry was a full computer. I remember when it first launched it was marketed as a platform for kids to learn python. Yet I think I somewhere seen someone mention that they used it as a server and I just wanted to double check.

I don't want to use my other computers as servers because it could be a risk and I need them for work. With a raspberry if something happens the cost of fixing it should remain low; unless my house burns down.:)

 

I have been reading up on the raspberry and it does look like a good option for a starter server, so I am going ahead with it.

2 hours ago, Scouting Ninja said:

I don't want to use my other computers as servers because it could be a risk and I need them for work.

You're right that your server should not also be a workstation, for a whole bunch of reasons.  Consider though that as soon as you open the ports and invite connections into machines in your home, there's going to be some amount of risk involved.  What you could do is get one of those VPS-style hosting services like Digital Ocean or Linode or something and deploy your server on one of those.  You won't be inviting connections into your home network, don't have to worry about weird port forwarding or asking for a static IP from your home internet provider, etc.- but they do cost about $5/month minimum to keep them running.

Edit:  Also, consider that security on a server like that is hard to get right if you don't already know what you're doing- so offloading that task to a machine with nothing else of value on it would be a good idea.

Yeah your home router/ISP is a more troublesome issue than whether your server is a Pi or a PC :)

Many ISPs actually have a clause in the fine print that hosting any kind of service is not allowed ("please upgrade to a business plan"), so be aware that you might be sneakily doing something that could get you cut off. Likewise most ISPs will change your IP every time your router reboots, which is very bad when trying to maintain a stable server.

You can get free trials of virtual server hosting on Amazon or Azure. If you don't expect longevity you might be done by the time the trial runs out. Alternatively, you can get a virtual server with similar performance to a Pi but in a datacenter with a 1Gbps internet connection for under $5/month.. 

Thanks for the advice. I contacted my service provider to check if I would be allowed to host, I explained to them what I needed and found out that under my current contract I would NOT have been allowed to host the server.

It turns out that switching to a contract where I can host costs less than $1 extra and gives me 2GB cloud storage with limited bandwith. I also had to remove a restriction on my modem that they guided me APN restriction?

They reassured me it isn't only for websites, a concern I had when they provided me with website building tools. I don't know how I feel about it.

 

On the one hand I now have every thing I need to keep score and store profiles, with good options to upgrade, don't need to maintain and it all costs less than a single dollar.

On the other hand I still have no idea how any of this works. They gave me software and some example code(Java and C++) to show how I would store data. That part works I made a C++ program to test.

 

I wonder if I should now still get the raspberry just to learn networking, then at the same time would I ever need to?

Yes, a Raspberry Pi can be a "server" because a "server" is just a computing machine that responds to requests from other nodes on the internet according to some rules that you decide. A Raspberry Pi 1 is probably about the same compute power as the server computers that ran the game EverQuest, one of the first really big MMOs (back in 2000 or so.) That being said, a Raspberry Pi does not allow you to hook up very durable media -- the compact flash is not designed for constant reading/writing over long times. Perhaps a hard disk on USB could solve that?

What's harder is to figure out how those other machines would find your server. If you have a typical home Internet service, you have a single IP address, and that address goes to your router. You'd then have to port forward from the router to your Raspberry Pi. You'd then have to register a domain name, and make it map to your IP address. And, when your ISP changes your home IP address (which happens automatically every so often without warning or notice,) you'd have to update the DNS to map to the new address, and wait for DNS caching to expire, so some users couldn't find your server for a while.

This is why servers live in data centers. They can have a fixed IP address, and a squirrel chewing on your internet wire won't knock you offline, and a heatwave won't make your home computer suddenly overheat while you're not even there to do anything about it.

Using a web host of some sort is much easier. Even better is something like a virtual private server -- be it Linode ($10/month,) interserver ($6/month,) or Amazon Lightsail ($5/month and up, plus networking fees.) Of course, as your server needs grow, you will need to pay more for the server hosting.

 

So, your web hosting provider has a plan that lets you "host" somehow? It's hard to tell exactly what that means. It might be a small container / virtual machine. At that point, you could build your own service using whatever tech you want (C++, node.js, golang, python, erlang, C#, Java, Haskell, PHP, ...) and have your apps talk to your service. You still need to register a domain name, and make "api.yourgamename.com" or somesuch point to that server's IP.

Or you can use Game Center on iOS and Google Play Services on Android. Sounds simpler :-)

enum Bool { True, False, FileNotFound };
11 hours ago, Scouting Ninja said:

I wonder if I should now still get the raspberry just to learn networking, then at the same time would I ever need to?

If you're looking to get into server development and management, get yourself VirtualBox (or VMWare) and set up local test servers as virtual devices on a local workstation in a virtual network.  You can play with everything you need that way, with backups (in case you mess up) and easy restarts (in case you mess up).  Study up on using Docker to wrap and provide your services, and that way you can build and test on your local  workstation-encapsulated server network and then migrate (publish) to your live server, with minimal risk and without change.

If you want to get a Pi, get a Pi.  You don't need a Pi to do any server development.  You can even run Docker on a Pi if you're serious about using one as a server.

Stephen M. Webb
Professional Free Software Developer

This topic is closed to new replies.

Advertisement