[Mirror] Run multiple clients on one machine

Hi all,

I am using Mirror to develop a multiplayer game. For testing purposes I want to be able to run multiple clients on my desktop. This is something I am sure I have done before in the past. Typically I would build my game as a Windows exe and run that, then also run the game in the Unity Editor. I could then have either of them spin up a host so the other can join as a client. However, when I try this, any message I try to send from the server to one client ends up being sent to both. I assume this is because both clients have the same address i.e. localhost. I could readily hack around this but am I missing something? Is there an intended way to solve this?

Thanks!

While Ive not used mirror more than a quick poke, Im sure there is a UID per player, how are you sending the message to the player?

You can use ParrelSync to run multiple clones of the editor for multiplayer testing. Unity has Multiplayer Playmode which is better and less resource intensive but I don’t know if this works with external networking solutions.

That sounds like an issue with Mirror really. If you have no client running, just the server, and send an RPC then the server ought to know that this message was sent by yours truly and discard it. If you can still receive the message with just the server running, there’s an issue.

If it takes the client instance running for message duplication to occur, perhaps you are inadvertently sending the server message back respectively you’re sending the message twice ie on keypress both instances respond by sending the same message simultaneously.

The RPC system shouldn’t allow you to specify IP targets but perhaps you’re using a low level system?

Thanks for the reply! Yeah this isn’t an RPC issue as I am sending custom messages directly using the NetworkConnection’s Send function;

Mirror Networking: Mirror.NetworkConnection Class Reference

So my call looks like this (@bugfinders):

    public static void SendToClient<MessageType>(NetworkConnectionToClient aClient, MessageType aMessage) where MessageType : struct, LoggableMessageInterface
    {
        string msgText = aMessage.GetLogText();
        Logger.Log("Sending " + typeof(MessageType).Name + " message to client '" + aClient.identity.name + "' ; " + msgText,
            Logger.MessageType.Info,
            aDisplay: false);

        aMessage.SetGameID(GameServer.Instance.State.GameID);
        aClient.Send(aMessage);
    }

I don’t think I am duplicating the send call but will keep debugging. I assign all players a unique ID so, as a work around, I am tempted to include the intended recipient’s id in all messages and then just discard any messages that arrive in the wrong place. A horrible hack but given that this only happens with multiple clients on one machine (a situation I don’t intend to support outside of debugging), I could put up with it but would rather find a proper fix.

The documentation you show of Send, doesnt seem to target a specific client, so I would expect it to send to all but maybe itself.. However, this seems relevant mirror how to send data to specific client? if you are trying to send to a specific client (as you seem surprised it went to all)

That Send method is on the NetworkConnection class i.e. sends to that specific connection. However I have solved the issue. It was a stupid mistake in my code. I was overwriting the data I was creating the messages from so they weren’t actually being received by both clients, it just seemed that way because the messages they were receiving contained duplicated content. Thanks for the suggestions but I will close this!