Network Class in it's minimal form with messages. Is this all a bit too over engineered?

I stumbled across the Network class (Unity - Scripting API: Network)

This contains some really nice functions like InitializeServer and Connect(string GUID) and they work well, so far so good.

I can create my server, I can connect to it with a client. And then from here all I want to do is Send a network packet with the information I want from server to clients or client to server, which seems like it would be a basic thing to do.

I see the documentation for Network.AllocateViewID() has some promising looking sample code (Unity - Scripting API: Network.AllocateViewID) but then I find that NetworkView is out of date. (https://docs.unity3d.com/Manual/class-NetworkView.html)

From there it seems like I should be using https://docs.unity3d.com/ScriptReference/Networking.NetworkIdentity.html - Which then looks likes it’s all for syncing objects between client and servers and all I want is to be able to do something like:

Network.Send(…)
and perhaps
Network.onMessageReceived += onNetworkMessageReceived

which might take a MessageBase derived object…

For anyone interested here is my use case:

  • I have an MMO game where users can own and race horses against each other.
  • My server (smartfox) will organize these players into a room with similarly experienced other horses.
  • When the room is ready to start the race. I would like the players to attempt to create a P2P connection to the player that smartfox has designated as the “host” for this race.
  • If the host leaves, it fails over to just sending the messages back via Smartfox to whoever is designated as the new host (Will abandon doing any P2P stuff here).

maybe look into NetworkServerSimple

I think that Network class you mentioned is legacy code (?)

1 Like