Hello all, first time asking a question here, some help would be greatly appreciated :)
TL;DR at the bottom.
I'm trying to use Unet's LLAPI to create an authoritative server system for my game. So far I've been able to use NetworkTransport on the server side and NetworkClient on the client side to establish connections. My intent was to have a single master server accepting connections, and then spawning additional game servers for each individual match.
When a client connects, they can request to create a new game. Server side, this will call NetworkTransport.AddHost() on a different port than the master server. This port number is sent back to the client, so they can connect to it. So far, this seems to be working.
The problem I'm encountering now, is when using NetworkTransport.Receive(). I seemingly can not receive on a single port / socket at a time. I would want each game server instance to only listen/receive on its own port. I can decide to only receive FROM a single client, but this isn't exactly what I'm looking for.
Additionally, my intent was to set up a connection with the LLAPI, but use the HLAPI (Commands, syncvars and clientRPC's primarily) to code the actual game, in order to avoid having to worry about setting up a good system for abstracting the serialization of data sent across the network. As such, I would want commands and clientRPCs that are sent to ONLY go to the port/socket of the game server that the client is actually playing on. This way clients can have their independent games without messages from other games interfering with what they're doing.
As Unet is very new, I understand there is not much information on it. Does anybody know if what I'm attempting is actually possible? If so, where am I going wrong?
I have considered that it might work if I use a separate unity instance for each game server, as they would each have their own static NetworkTransport instance, but this creates a whole load of other issues concerning inter-process communication. Would this, in theory, be a viable solution?
Another potential solution that has occured to me is keeping a list of clients that are on game servers, and manually ignoring any messages from them on the master server Receive(). With many clients, this doesn't seem like a good solution performance-wise, however. A game server, though, could the simply call ReceiveFromHost() for each client it knows is connected to it. At this time, however, I don't know (have not tested) whether Commands and ClientRPCs wouldn't still go to every game server instance?
I realize this is quite a wall of text, thanks for reading :)
How do I receive network messages on a single port/socket only, using NetworkTransport.Receive() and Commands/ClientRPCs?
Hello, did you find your solution on this?
No, unfortunately I never did. I am no longer working on this project.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
4 People are following this question.
C# TCP server -- cannot call methods or set variables
How to synchronize disable and enabling game objects over the network?
Multiple Cars not working
Distribute terrain in zones
This is only activating the hat locally or an all clients or no clients.