示例#1
0
 private void Initialize()
 {
     Log.Debug("Setup UDP Client");
     _localEndPoint = new IPEndPoint(IPAddress.Any, LocalPort);
     _udpClient     = new UdpClient(_localEndPoint);
     _localEndPoint = _udpClient.Client.LocalEndPoint as IPEndPoint;
     LocalPort      = _localEndPoint?.Port ?? 0;
     Log.Debug($"Local Port {LocalPort}");
     manager = new RaceManager();
 }
示例#2
0
        static void Main(string[] args)
        {
            RaceManager MyRaceManager = new RaceManager();

            MyRaceManager.start();
            //   Console.WriteLine("Hello World!");
            //  Communicator communicator = new Communicator(12000);
            // communicator.Start();
            //while (!communicator.IsMessageAvailable())
            //    Console.WriteLine("Message Not Ready");

            //Console.WriteLine("Message Ready:");

            //Console.ReadKey();
        }
示例#3
0
        public void Process(string[] Message, ref RaceManager _MyRaceManager, System.Net.IPEndPoint senderEndPoint)
        {
            _MyRaceManager.RaceName     = Message[1];
            _MyRaceManager.CourseLength = Convert.ToDouble(Message[2]);
            _MyRaceManager.RaceStarted  = true;

            //Race,< race name >,< course length in meters >
            string message = "Race," + _MyRaceManager.RaceName + "," + _MyRaceManager.CourseLength;

            foreach (var ob in _MyRaceManager.MyClients)
            {
                //ob.Update();
                _MyRaceManager.MyCommunicator.Send(message, ob.MyEndPoint);
            }
            //Here is where all the communication logic would go
        }
示例#4
0
 public void Process(string[] Message, ref RaceManager _MyRaceManager, System.Net.IPEndPoint senderEndPoint)
 {
     foreach (var client in _MyRaceManager.MyClients)
     {
         if (client.MyEndPoint.Address == senderEndPoint.Address && client.MyEndPoint.Port == senderEndPoint.Port)
         {
             foreach (var runner in _MyRaceManager.MyRunners)
             {
                 if (Convert.ToInt32(Message[1]) == runner.bibNumber)
                 {
                     runner.Detach(client);
                     runner.Notify("Detach", runner);
                 }
             }
         }
     }
 }
示例#5
0
 public void Process(string [] Message, ref RaceManager _MyRaceManager, System.Net.IPEndPoint senderEndPoint)
 {
     foreach (var client in _MyRaceManager.MyClients)
     {
         if (client.MyEndPoint.Address.Equals(senderEndPoint.Address) && client.MyEndPoint.Port.Equals(senderEndPoint.Port))
         {
             foreach (var runner in _MyRaceManager.MyRunners)
             {
                 if (Convert.ToInt32(Message[1]) == runner.bibNumber)
                 {
                     runner.Attach(client);
                     runner.Notify("Attach", runner);
                 }
             }
         }
     }
     //Since I can't get the communicator working, we'll pretend that the message is
     //in this order unsubscribe,bibnumber,ipaddress,endpoint
 }
        public void Process(string[] Message, ref RaceManager _MyRaceManager, System.Net.IPEndPoint senderEndPoint)
        {
            Athlete MyAthlete = new Athlete();

            MyAthlete.bibNumber = Convert.ToInt32(Message[1]);
            MyAthlete.startTime = Convert.ToDouble(Message[2]);
            MyAthlete.firstName = Message[3];
            MyAthlete.lastName  = Message[4];
            MyAthlete.gender    = Message[5];
            MyAthlete.age       = Convert.ToInt32(Message[6]);

            _MyRaceManager.MyRunners.Add(MyAthlete);
            string message = "Athlete," + MyAthlete.bibNumber + "," + MyAthlete.firstName + "," + MyAthlete.lastName + "," + MyAthlete.gender + "," + MyAthlete.age;

            foreach (var client in _MyRaceManager.MyClients)
            {
                _MyRaceManager.MyCommunicator.Send(message, client.MyEndPoint);
            }
            //here is where the communication logic would go
        }
示例#7
0
        public void Process(string[] Message, ref RaceManager _MyRaceManager, System.Net.IPEndPoint senderEndPoint)
        {
            Client client = new Client(senderEndPoint);

            _MyRaceManager.MyClients.Add(client);
            if (_MyRaceManager.RaceStarted)
            {
                string OutGoingMessage1 = "Race," + _MyRaceManager.RaceName + "," + _MyRaceManager.CourseLength;
                _MyRaceManager.MyCommunicator.Send(OutGoingMessage1, client.MyEndPoint);
            }
            if (_MyRaceManager.MyRunners.Count != 0)
            {
                foreach (var runner in _MyRaceManager.MyRunners)
                {
                    string OutGoingMessage2 = "Athlete," + runner.bibNumber + "," + runner.firstName + "," + runner.lastName + "," + runner.gender + "," + runner.age;
                    _MyRaceManager.MyCommunicator.Send(OutGoingMessage2, client.MyEndPoint);
                }
            }
            //Usually the communicator would have the ip and endpoint info,
            //but since I can't get it working, we'll pretend that the message
            // is hello,ip,endpoint.
        }
 public void Process(string[] Message, ref RaceManager _MyRaceManager, System.Net.IPEndPoint senderEndPoint)
 {
     foreach (var athlete in _MyRaceManager.MyRunners)
     {
         if (athlete.bibNumber == Convert.ToInt32(Message[1]))
         {
             athlete.lastUpdatedTime = Convert.ToDouble(Message[2]);
             athlete.finishTime      = athlete.lastUpdatedTime;
             athlete.status          = "DidNotFinish";
             string outGoingMessage = "Status," + athlete.bibNumber + "," + athlete.status + "," + athlete.startTime + "," + athlete.distanceCovered + "," + athlete.lastUpdatedTime + "," + athlete.finishTime;
             foreach (var client in _MyRaceManager.MyClients)
             {
                 foreach (var subject in client.MyAthleteSubjects)
                 {
                     if (subject.bibNumber == athlete.bibNumber)
                     {
                         _MyRaceManager.MyCommunicator.Send(outGoingMessage, client.MyEndPoint);
                     }
                 }
             }
         }
     }
 }