Beispiel #1
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            UdpClient  listener = new UdpClient(listenPort);
            IPEndPoint groupEP  = new IPEndPoint(IPAddress.Any, listenPort);

            try
            {
                Console.WriteLine("Waiting for broadcast");
                while (true)
                {
                    byte[] bytes   = listener.Receive(ref groupEP);
                    var    payload = Encoding.ASCII.GetString(bytes, 0, bytes.Length);
                    var    vector  = _packetParser.Convert(payload);
                    _motorController.Move(vector);
                    //vector.Dump();
                }
            }
            catch (SocketException e)
            {
                Console.WriteLine(e);
            }
            finally
            {
                listener.Close();
            }
            return(Task.CompletedTask);
        }