예제 #1
0
파일: Connections.cs 프로젝트: Omybot/GoBot
        /// <summary>
        /// Ajoute une connexion UDP aux connexions suivies
        /// </summary>
        /// <param name="board">Carte associée à la connexion</param>
        /// <param name="ip">Adresse IP de la connexion</param>
        /// <param name="inPort">Port d'entrée pour le PC</param>
        /// <param name="outPort">Port de sortie pour le PC</param>
        /// <returns>La connexion créée</returns>
        private static UDPConnection AddUDPConnection(Board board, IPAddress ip, int inPort, int outPort)
        {
            UDPConnection output = new UDPConnection();

            output.Connect(ip, inPort, outPort);
            UDPBoardConnection.Add(board, output);
            EnableConnection.Add(board, true);
            AllConnections.Add(output);
            output.ConnectionChecker.SendConnectionTest += ConnexionCheck_SendConnectionTestUDP;

            return(output);
        }
예제 #2
0
    protected override void OnEvent(Event e)
    {
        switch (e.Type)
        {
        case "MatchPlace":
            Debug.Log("We Have Match Port");
            PlayerInfo.PlayerData.MatchIP   = e.Info["matchIP"];
            PlayerInfo.PlayerData.MatchPort = int.Parse(e.Info["matchPort"]);
            _matchTcp.Connect(PlayerInfo.PlayerData.MatchIP, PlayerInfo.PlayerData.MatchPort);
            _matchUdp.Connect(PlayerInfo.PlayerData.MatchIP, PlayerInfo.PlayerData.MatchPort);
            _messageHandler.TCPHandshake();
            _messageHandler.UDPHandshake();

            break;

        case "MatchUpdate":
            GameObject o = GameObject.Find(e.Info["Id"]);
            if (o == null)
            {
                Debug.Log("Object " + e.Info["Id"] + " Not Found");
                return;
            }

            o.GetComponent <NetworkDriven>().SetTarget(float.Parse(e.Info["X"]), float.Parse(e.Info["Y"]),
                                                       Mathf.Rad2Deg * float.Parse(e.Info["Angle"]));
            break;

        case "MatchStart":

            break;

        case "FakeID":
            Debug.Log("Fake ID Received");
            PlayerInfo.MatchPlayerID = int.Parse(e.Info["id"]);
            break;

        case "HeroID":
            PlayerInfo.HeroName = e.Info["HeroID"];
            GameObject hero = GameObject.Find(PlayerInfo.HeroName);
            if (hero != null)
            {
                Camera.main.GetComponent <MatchCamera>().target = hero.transform;
            }
            break;

        case "MatchEnd":
            MessageHandler.i.GetPlayer(PlayerPrefs.GetString("id"));
            Debug.Log("Match Ended");
            SceneManager.LoadScene("MenuScene");
            break;
        }
    }
예제 #3
0
        public bool CreateChannelUDP()
        {
            bool ok = false;

            try
            {
                Dictionary <String, String> rep = _comm.SendCommand(PepperlCmd.CreateChannelUDP,
                                                                    PepperlConst.ParamUdpAddress, FindMyIP().ToString(),
                                                                    PepperlConst.ParamUdpPort, _port.ToString(),
                                                                    PepperlConst.ParamUdpWatchdog, PepperlConst.ValueUdpWatchdogOn,
                                                                    PepperlConst.ParamUdpWatchdogTimeout, _timeout.TotalMilliseconds.ToString(),
                                                                    PepperlConst.ParamUdpPacketType, PepperlConst.ValueUdpPacketTypeDistanceAmplitudeCompact);

                if (rep != null)
                {
                    _handle = rep[PepperlConst.ParamUdpHandle];

                    if (_handle != "")
                    {
                        _udp = new UDPConnection();
                        _udp.Connect(_ip, _port, _port + 1);
                        _udp.StartReception();
                        _udp.FrameReceived += _udp_FrameReceived;

                        _comm.SendCommand(PepperlCmd.ScanStart,
                                          PepperlConst.ParamUdpHandle, _handle);

                        ok = true;
                    }
                }
            }
            catch (Exception)
            {
                ok = false;

                if (_udp != null && _udp.Connected)
                {
                    _udp.Close();
                    _udp = null;
                }
            }

            return(ok);
        }