Ejemplo n.º 1
0
        public void Start()
        {
            if (this.timer != null)
            {
                this.timer.Dispose();
                this.sock.Close();
                this.sock.Dispose();
            }

            this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            this.sock.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, 1);
            this.ip   = Broadcaster.getOwnIP();
            this.data = Encoding.ASCII.GetBytes("PresenceSimulator:" + ip);
            this.dest = new IPEndPoint(IPAddress.Broadcast, Properties.Settings.Default.BroadcastPort);

            AutoResetEvent autoEvent = new AutoResetEvent(false);

            this.timerDelegate = new TimerCallback(this.broadcast);
            this.timer         = new Timer(timerDelegate, autoEvent, 0, this.period);
        }