Search Unity

Third Party Socket Exception with Playfab mp example when updating Mirror from 43.3.1 to 43.4.3 (Telepathy)

Discussion in 'Multiplayer' started by samhain323, Feb 20, 2022.

  1. samhain323

    samhain323

    Joined:
    Aug 4, 2020
    Posts:
    10
    Edit: Seem to have found a solution. Turned off autobuild and changed some of the NeworkServer calls to NetworkManager calls instead. Thanks to Solias on the Mirror Discord.


    I'm developing my networking game flow based off these two projects using Unity, Mirror, and Playfab.

    https://github.com/natepac/playfabmirrorgameexample/tree/master

    https://github.com/PlayFab/MpsSamples/tree/master/UnityMirror

    I'm using a game configuration object in this version. If there is no IP in the configuration, I call PlayFabMultiplayerAPI.RequestMultiplayerServer and add the IP and Port to the network manager, then connect. I get the correct information, but seem to be immediately disconnected (client times out). When I use the same information directly in the configuration and skip the call to RequestMultiplayerServer, I connect and have no issues.


    I started testing locally using the Playfab LocalAgent. I found that I'm getting socket exceptions after changing to certain versions of Mirror. In the server build, the network manager starts up, then the example code calls NetworkServer.Listen() (which would be the second time it's called) and then I get the exception.

    This is the second call :
    Code (CSharp):
    1.         public void StartListen()
    2.         {
    3.             NetworkServer.Listen(base.maxConnections);
    4.         }

    Edit: At Mirror version 43.3.1, Telepathy works fine, but KCP gets the socket exception, once I get to 43.4.5, both Telepathy and KCP have the issue. The main change between those versions seems to be the code involving calling Telepathy.Client and Telepathy.Server

    Code (CSharp):
    1.             // create client & server
    2.             client = new Telepathy.Client(clientMaxMessageSize);
    3.             server = new Telepathy.Server(serverMaxMessageSize);

    I'm assuming that KCP probably already had similiar changes prior to 43.3.1, which is why it gets the exception and Telepathy doesn't. I'm not really sure how to fix the example code to get it to work. I've tried making the second call only if NetworkServer isn't active, but that didn't help, nor did taking it out entirely (well, I avoided the socket exception, but it didn't work properly otherwise).

    I've attached the two versions of the telepathy files in the comments section below.







    Mirror version up to 43.3.1 using Telepathy
    ---First init call ---

    [AgentListener].ReadyForPlayers:
    Server: Start port=7777
    Server started listening
    Server: listening port=7777

    ---Second init call---
    [AgentListener].OnServerActive: Server Started From Agent Activation
    [NetworkServer].Initialize: True
    Server started listening
    NetworkServer.RegisterHandler replacing handler for Mirror.ReadyMessage, id=40252. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
    NetworkServer.RegisterHandler replacing handler for Mirror.CommandMessage, id=46228. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
    NetworkServer.RegisterHandler replacing handler for Mirror.NetworkPingMessage, id=33151. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
    Operation: Active, Maintenance:, State: Active
    Timer:1.001643 - Max:1


    Mirror version up to 43.3.1 using KCP
    ---First init call ---

    [AgentListener].ReadyForPlayers:
    Server started listening

    ---Second init call---
    [AgentListener].OnServerActive: Server Started From Agent Activation
    KCP: server already started!
    SocketException: Address already in use
    at System.Net.Sockets.Socket.Bind (System.Net.EndPoint localEP) [0x00043] in <1e1a09bd7c4e407788af79f6b1d8f250>:0
    at kcp2k.KcpServer.Start (System.UInt16 port) [0x0004c] in <985ad75dad8b4a6b9e2f2da75b9216bc>:0
    at kcp2k.KcpTransport.ServerStart () [0x00000] in <0704e813136943d5a0c391d4a54725c5>:0
    at Mirror.NetworkServer.Listen (System.Int32 maxConns) [0x00012] in <0704e813136943d5a0c391d4a54725c5>:0
    at PlayFab.Networking.UnityNetworkServer.StartListen () [0x00000] in <7c490d63c856423482a7fde1479128ea>:0
    at AgentListener.OnServerActive () [0x0000f] in <7c490d63c856423482a7fde1479128ea>:0
    at PlayFab.PlayFabMultiplayerAgentAPI.ProcessAgentResponse (PlayFab.MultiplayerAgent.Model.HeartbeatResponse heartBeat) [0x000e5] in <8ca7d763c9dc4672a8f4ac2aa2a88c4e>:0
    at PlayFab.PlayFabMultiplayerAgentAPI+<SendHeartBeatRequest>d__51.MoveNext () [0x00277] in <8ca7d763c9dc4672a8f4ac2aa2a88c4e>:0
    at UnityEngine.SetupCoroutine.InvokeMoveNext (System.Collections.IEnumerator enumerator, System.IntPtr returnValueAddress) [0x00026] in <ad199b1c67244da3a5ed230e5d202f21>:0





    Mirror version 43.4.3 and higher Telepathy
    ---First init call ---

    [AgentListener].ReadyForPlayers:
    Server: Start port=7777
    Server started listening
    Server: listening port=7777

    ---Second init call---

    [AgentListener].OnServerActive: Server Started From Agent Activation
    Server: Start port=7777
    Server started listening
    NetworkServer.RegisterHandler replacing handler for Mirror.ReadyMessage, id=40252. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
    NetworkServer.RegisterHandler replacing handler for Mirror.CommandMessage, id=46228. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
    NetworkServer.RegisterHandler replacing handler for Mirror.NetworkPingMessage, id=33151. If replacement is intentional, use ReplaceHandler instead to avoid this warning.
    Operation: Active, Maintenance:, State: Active
    Server Thread stopped. That's okay. System.Net.Sockets.SocketException (0x80004005): Address already in use
    at System.Net.Sockets.Socket.Bind (System.Net.EndPoint localEP) [0x00043] in <1e1a09bd7c4e407788af79f6b1d8f250>:0
    at System.Net.Sockets.TcpListener.Start (System.Int32 backlog) [0x00044] in <1e1a09bd7c4e407788af79f6b1d8f250>:0
    at System.Net.Sockets.TcpListener.Start () [0x00000] in <1e1a09bd7c4e407788af79f6b1d8f250>:0
    at Telepathy.Server.Listen (System.Int32 port) [0x00022] in <0fdbdfcf1e104978bc71fb54f73b8bd7>:0
    Timer:1.001659 - Max:1






    Any help would be greatly appreciated
     
    Last edited: Feb 21, 2022
  2. samhain323

    samhain323

    Joined:
    Aug 4, 2020
    Posts:
    10
    Here are the two files for comparision
     

    Attached Files:

  3. amankAtUnity

    amankAtUnity

    Joined:
    Jan 27, 2019
    Posts:
    20
    Facing the same problem:

    NetworkServer.RegisterHandler replacing handler for Mirror.ReadyMessage, id=40252. If replacement is intentional, use ReplaceHandler instead to avoid this warning.

    How did you solve it?