Ejemplo n.º 1
0
        private void ReceiveInfo()
        {
            // Get Port from app.config or use default :9050
            int port = 0;

            Int32.TryParse(ConfigurationManager.AppSettings["port"], out port);
            if (port == 0)
            {
                port = 9050;
            }

            var ServerEndPoint = new IPEndPoint(IPAddress.Any, port);
            var socket         = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            // TODO: SocketException might happen here
            socket.Bind(ServerEndPoint);
            var sender = new IPEndPoint(IPAddress.Any, 0);
            var Remote = (EndPoint)(sender);

            while (true)
            {
                try
                {
                    byte[] data = new byte[128];

                    int    recv    = socket.ReceiveFrom(data, ref Remote);
                    string message = Encoding.ASCII.GetString(data, 0, recv);

                    MusicInfo info = ParseDataToInfo(message);

                    ReceivedInfo?.Invoke(this, new ReceiveEventArgs(info));
                }
                catch (Exception)
                {
                    continue;
                }
            }
        }
Ejemplo n.º 2
0
 public ReceiveEventArgs(MusicInfo info)
 {
     this.Info = info;
 }