- Home /
Run Multiple Dedicated servers
I am trying to make a social media app in unity (I know its not the best option to be using unity, but im most familiar with it and I don't want to learn a new type of programming) The way the social media app will run will be that you can create a party where you can invite friends and post inside that party. My issue is im not sure how I can run so many parties as individual servers and how it will have to create a new server every time. Also im not sure how I could keep the server running if the host of the party leaves the app. If anyone could think of some type of a solution it would be a lot of help. Thanks!
Don't run a new server each time. Have one server and each time a new party is formed, start a new thread.
How would I make it so that a player could only see one thread when they accept an invite to a thread?
Whenever you make a request to the server, require a key. The server would then need to manage all its parties in a way that only the key can link into the party.
You can separate the server update threads from the data, so you get really nice async.
Put together, it's probably something like
private Hash$$anonymous$$ap<string, Party> parties;
// When the server gets a request for a party, it tries to return this
public PartyData GetParty(string key)
{
if (!parties.Contains$$anonymous$$ey(key))
{
return null;
}
else
{
return parties[$$anonymous$$ey].data;
}
}
(but don't actually use that, it's pseudocode.)
Answer by Strixie13 · Aug 15, 2018 at 10:20 PM
There are two main types of models you can do. Client-Server is where YOU own a server that runs the software and people connect. The other method is peer-to-peer, which involves passing around the "hosting" responsibilities automatically until nobody is left in the room. IE if person 3 was hosting the room and left, everyone would then connect to person 2 instead.
Keep in mind that you can have multiple groups on one physical server. Most MMOs have multiple areas and instances of people grouped up, but they all connect to the same server. It just redirects traffic. So don't think in terms of multiple servers. You will probably only have one, and then divide people up into groups ON that server.
This is a lot of networking stuff that you would need to learn. If you are hard pressed to keep to Unity it can definitely be done. Just a heads up, the time to learn all the networking code and do it through a game engine will take significantly more time than learning a few web languages and following the more traditional route.
Answer by Glurth · Aug 15, 2018 at 10:44 PM
I would suggest something like this:
- Allow each user to join any number of "Parties"; this can be stored on the server as a list of party-names, along with the user's name and connectionID.
- Users may send a message to any party they have joined. (However you might choose to do UI for this.)
- This message is sent to the server, containing the text of the message, but, the client will automatically add the name of the destination party (like a header). Note: you may need to do some "encoding", for this, e.g. specify the message sent from client to the server will always be of the format:
partyname|somecookydelimeter|the text of the message
(Or better yet, include this information in your MessageBase derived class)
-When the message is recieved, the server then finds all the logged on users, that have joined this party, and send the message to ONLY these users. (e.g. Rather than use NetworkServer.SendToAll, you can use multiple calls to NetworkServer.SendToClient )
-Expand on the concept to allow sending a message to multiple-joined-parties, at once. e.g.
partyname|pdel|party2|pdel|party3|somecookydelimeter|the text of the message
(Or better, add a List/< string /> member to your MessageBase derived class.)
Your answer
Follow this Question
Related Questions
Custom dedicated server application 3 Answers
Do player hosted servers cost me money to run? 1 Answer
Load Image from an dedicated computer server 1 Answer
Unity networking tutorial? 6 Answers