Going through tutorial and getting NotImplementedException: The method or operation is not implemented, on GetActiveUdpListeners ()

Getting NotImplementedException: The method or operation is not implemented.
System.Net.NetworkInformation.UnixIPGlobalProperties.GetActiveUdpListeners () (at <>:0) when going through the GameLift Mega Frog Tutorial, when I try to connect to or create a server. Can’t figure out what I need to do here. This should be implemented in the .dll that the tutorial is using, right?

https://aws.amazon.com/blogs/gametech/creating-servers-for-multiplayer-mobile-games-with-amazon-gamelift/?sc_channel=el&sc_campaign=rts-blog&sc_publisher=gamelift&sc_medium=featuresblog&sc_detail=learnbutton&sc_content=blog&sc_country=global&sc_geo=global&sc_category=gamelift&sc_segment=features&sc_outcome=gamedev

Can you confirm your OS and Unity version?

I am going to assume you are on Mac OS X and are seeing issues in FindAvailableUDPPort

Looks like Unity is trying to link against this:

https://github.com/mono/mono/blob/master/mcs/class/System/System.Net.NetworkInformation/UnixIPGlobalProperties.cs#L100

and it appears Mono on Unix platforms just doesn’t implement this feature.

As the Megafrog code is just trying to find an open UDP port, the workaround here is fairly straightforward. You could either:

  1. Return a hard-coded UDP open port
  2. Use the examples here (which reference TCP but many should work with TCP) to build alternative code: https://stackoverflow.com/questions/138043/find-the-next-tcp-port-in-net
  3. The example from Eric Boumendil should be easy to modify to use Udp
  4. Basically rely on the properties of port 0, and the network adapters should find you the next open port
    I have filed an internal bug to fix the example on Mac OS X. Apologies for the inconvenience.

Better fix: GameLift Server kicks player because of no response to ping

(Only just seen - we’re obviously going through the same issue at the same time!)


Original Response:

As of Sept 2020, this is still in the sample code. Here is a simple fix based on Pip’s details above.

Replace the function “FindAvailableUDPPort” with

    private int FindAvailableUDPPort(int firstPort, int lastPort)
{

    try
    {
        var UDPEndPoints = IPGlobalProperties.GetIPGlobalProperties().GetActiveUdpListeners();
        List<int> usedPorts = new List<int>();
        usedPorts.AddRange(from n in UDPEndPoints where n.Port >= firstPort && n.Port <= lastPort select n.Port);
        usedPorts.Sort();
        for (int testPort = firstPort; testPort <= lastPort; ++testPort)

        {
            if (!usedPorts.Contains(testPort))
            {
                return testPort;
            }
        }
    } catch
    {
        Debug.Log("You must be on a Mac or Unix");
        TcpListener l = new TcpListener(IPAddress.Loopback, 0);
        l.Start();
        int port = ((IPEndPoint)l.LocalEndpoint).Port;
        l.Stop();
        return port;
    }
    return -1;
}

You’ll need to add references for System.Net (‘using System.Net’) as the top.