Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

NetworkServer.SendToAll *not* sending message to local client?

Discussion in 'Multiplayer' started by Chris-Crafty, Jul 21, 2015.

  1. Chris-Crafty

    Chris-Crafty

    Joined:
    May 7, 2013
    Posts:
    27
    I'm trying to use NetworkServer.SendToAll to send a custom "preparegame" message from the server to all connected clients. That works, except that the local client doesn't receive the message. Is that a bug or for some reason that I don't quite understand intentional? I'm quite sure that the local client is listening for the message.
     
  2. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    it should be sent to the local client. when are you sending it?
     
  3. Chris-Crafty

    Chris-Crafty

    Joined:
    May 7, 2013
    Posts:
    27
    Players are connected to a custom lobby, sending the message occurs (or should occur) when the host clicks a "Start Game" button. Message is correctly received by connected remote client player objects that are listening to it (both the authorative and non-authorative ones) but not by the local client objects.
     
  4. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    is the handler registered for the local client?
     
  5. Chris-Crafty

    Chris-Crafty

    Joined:
    May 7, 2013
    Posts:
    27
    Yes it is - AFAIK I would get an "network message unknown" error if it wasn't.
     
  6. Deleted User

    Deleted User

    Guest

    Code (csharp):
    1.  
    2. if (client.isConnected)
    3.   {
    4.   //this will execute for the client (if youre the host, this will also run).
    5.   client.RegisterHandler(MyMsgType.MessageData, RecieveMessage);
    6.   }
    7.   if (isServer)
    8.   {
    9.   //this will execute for server (if youre the host, this will also run).
    10.   NetworkServer.RegisterHandler(MyMsgType.MessageData, RecieveMessage);
    11.   }
    12.  
    If youre host, the client and server will register the handler.
     
    anarbek likes this.
  7. standardcombo1

    standardcombo1

    Joined:
    Sep 18, 2015
    Posts:
    1
    It seems that, if the connection is created by using NetworkServerSimple, NetworkServer.SendToAll() doesn't work. This was the case I ran into.
     
  8. thegreatzebadiah

    thegreatzebadiah

    Joined:
    Nov 22, 2012
    Posts:
    836
    @standardcombo1 if that's true then it must not work at all in 5.3 because the NetworkServer seems to mostly just be a wrapper for NetworkServerSimple now. I may be running into this issue now, or it may just be that I'm doing something dumb. I swear this was working before though.