Пример #1
0
        private static void Request(string host, Action <NetWorker> call)
        {
            if (Networking.Sockets != null && Networking.Sockets.ContainsKey(PORT))
            {
                Networking.Disconnect(PORT);
            }

            NetWorker socket = Networking.Connect(host, PORT, Networking.TransportationProtocolType.UDP, standAlone: true);

            socket.MasterServerFlag = true;

            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_REGISTER_SERVER, null);
            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_UNREGISTER_SERVER, null);
            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_UPDATE_SERVER, null);
            socket.AddCustomDataReadEvent(WriteCustomMapping.MASTER_SERVER_GET_HOSTS, GetHostsRequestToClient);

            if (socket.Connected)
            {
                call(socket);
            }
            else
            {
                socket.connected += delegate() { call(socket); }
            };
        }