-1

I'm looking into Unity multiplayer support. From all docs it seems like the main model is for a game to be capable of being both the server and the client, and the same binary used for both.

Would it be possible to make a game where the client and the server are two different binaries: client being more lightweight and only doing the client part, while server doing heavy lifting of handling the open world/gameplay/state etc.?

As a simplified example imagine a huge world populated by characters, and the client is a mobile app that only needs to display their health/stats and render their avatar. While on the server those characters live a complex life in a large environment.

2
  • Yes you can even using UNET (Unity multiplayer service), and you can also use another service not official to unity
    – Daahrien
    Commented Dec 1, 2017 at 10:00
  • That would be great. Can you point me to any resources that could help me get started with this approach?
    – Dennis K
    Commented Dec 1, 2017 at 15:03

2 Answers 2

1

You could use something like SmartFoxServer (supports unity3d) for the server operations completely independent of the client side logic. This is going to be C# Unity on the client and Java for SmartFoxServer. It is pretty easy to configure extensions, manage rooms, lobby, user events, chats etc in the server and get the events on the client side. You can build a complete MMO system and run it on mobile too.

2
  • So would this mean it's gonna be completely custom networking implementation not using the built in NetworkManager/Identity etc.?
    – Dennis K
    Commented Dec 1, 2017 at 15:01
  • On the server side, it would be nothing related to Unity3D. You will have to inherit the base extensions that SmartFoxServer provides, but yes, you can customise it the way you want.
    – Ajjo
    Commented Dec 1, 2017 at 16:22
1

So I believe I found a way, at least it's working for me. What I need is possible using NetworkClient and NetworkServer classes. So now I have two separate projects, server and client. Server has a script which is pretty much:

public class Server : MonoBehaviour {
public Text text;
public class HelloMessage : MessageBase
{
    public string helloText;
}

void Start () {
    NetworkServer.Listen(4444);
    NetworkServer.RegisterHandler(333, onHelloMessage);

}

public void onHelloMessage(NetworkMessage msg)
{
    text.text = msg.ReadMessage<HelloMessage>().helloText;
}
}

This listens for messages on port 4444.

Then the client side is like this: public class NetworkManager : MonoBehaviour { NetworkClient client;

public class HelloMessage : MessageBase
{
    public string helloText;
}

// Use this for initialization
void Start () {
    client = new NetworkClient();
    client.Connect("127.0.0.1", 4444);

}

public void SendNetworkMessage()
{
    HelloMessage msg = new HelloMessage();
    msg.helloText = "Hello";
    client.Send(333, msg);
}

}

Now on the server side we can hook up text to a label and on the client side SendNetworkMessage to a button and we can send messages from client to appear on the server.

Now just need to define a protocol and off we go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.