I got myself a working version with a somewhat smaller & ‘neater’ logic:
- The peer joins.
- The host takes notice from the OnPeerAdded event and broadcasts the string to all Peers (but to himself):
void OnPeerAdded(PeerAddedArgs args)
{
Debug.LogFormat("Peer joined: {0}", args.Peer.Identifier);
string str = $"MyText";
byte[] bytes = Encoding.ASCII.GetBytes(str);
if (_isHost)
_networking.BroadcastData(tag: (uint)_MessageType.SendPeerMessage, data: bytes, transportType: TransportType.UnreliableUnordered, sendToSelf: false);
}
- The peer receives the string at the OnDidReceiveDataFromPeer function, deserializes it, and calls the appropriate method. Like this:
....
case _MessageType.SendPeerMessage:
string str = Encoding.ASCII.GetString(data);
_controller.DoSomethingWithTheString(str);
break;
}
Case closed. Thanks.