Exemplo n.º 1
0
        protected void CloseConnection(object state)
        {
            CloseConnectionParam param = (CloseConnectionParam)state;

            if (param.CloseEvent == null)
            {
                Thread.Sleep(param.Timeout);
            }
            else
            {
                param.CloseEvent.WaitOne(param.Timeout);
            }
            param.Socket.Close();
            if (DiscoveryFinished != null)
            {
                DiscoveryFinished(this, EventArgs.Empty);
            }
        }
Exemplo n.º 2
0
        public void Probe(IPAddress address)
        {
            DiscoverySocket socket    = new DiscoverySocket(endPointLocal);
            bool            multicast = IsMulticast(address);

            if (multicast)
            {
                socket.JoinMulticastGroup(address);
            }
            string     probe    = BuildProbeMessage();
            IPEndPoint endpoint = new IPEndPoint(address, WS_DISCOVER_PORT);

            socket.Send(endpoint, probe);
            socket.MessageReceived += OnMessageReceived;
            socket.Listen();

            CloseConnectionParam task = new CloseConnectionParam(socket, WS_DISCOVER_MULTICAST_TIMEOUT);

            if (!multicast)
            {
                task.CloseEvent = socket.AnswerReceivedEvent;
            }
            ThreadPool.QueueUserWorkItem(CloseConnection, task);
        }