示例#1
0
    void Start()
    {
        if (mRequest == null)
        {
            mRequest = Buffer.Create();
            mRequest.BeginPacket(Packet.RequestServerList).Write(GameServer.gameID);
            mRequest.EndPacket();
        }

        if (mRemoteAddress == null)
        {
            mRemoteAddress = string.IsNullOrEmpty(remoteAddress) ?
                             new IPEndPoint(IPAddress.Broadcast, remotePort) :
                             Tools.ResolveEndPoint(remoteAddress, remotePort);

            if (mRemoteAddress == null)
            {
                mUdp.Error(new IPEndPoint(IPAddress.Loopback, mUdp.listeningPort),
                           "Invalid address: " + remoteAddress + ":" + remotePort);
            }
        }

        // Twice just in case the first try falls on a taken port
        if (!mUdp.Start(Tools.randomPort))
        {
            mUdp.Start(Tools.randomPort);
        }
    }