Exemplo n.º 1
0
        protected override void Discover()
        {
            var localIP       = UdpClient.GetLocalIPAddress();
            var localEndpoint = new IPEndPoint(IPAddress.Parse(localIP), 3672);

            DISCOVER_REQUEST[8]  = localEndpoint.Address.GetAddressBytes()[0];
            DISCOVER_REQUEST[9]  = localEndpoint.Address.GetAddressBytes()[1];
            DISCOVER_REQUEST[10] = localEndpoint.Address.GetAddressBytes()[2];
            DISCOVER_REQUEST[11] = localEndpoint.Address.GetAddressBytes()[3];
            DISCOVER_REQUEST[12] = (byte)(localEndpoint.Port >> 8);
            DISCOVER_REQUEST[13] = (byte)localEndpoint.Port;

            var udpClient = new UdpClient();

            udpClient.BindSocket(localEndpoint.Port.ToString());
            udpClient.DataReceived += SocketDataReceived;

            Task.Run(async() =>
            {
                await udpClient.Send(new HostName("224.0.23.12"), "3671", DISCOVER_REQUEST);
                await Task.Delay(5000);

                udpClient.DataReceived -= SocketDataReceived;
                udpClient.Dispose();
            });
        }
Exemplo n.º 2
0
        protected override void Discover()
        {
            var udpClient = new UdpClient();

            udpClient.DataReceived += SocketDataReceived;
            udpClient.BindSocket("67");

            Task.Run(async() =>
            {
                await udpClient.Send(UdpClient.BROADCAST_ADDR, "68", DISCOVER_REQUEST);
                await Task.Delay(5000);

                udpClient.DataReceived -= SocketDataReceived;
                udpClient.Dispose();
                udpClient = null;
            });
        }
Exemplo n.º 3
0
        protected override void Discover()
        {
            var udpClient = new UdpClient();

            udpClient.DataReceived += SocketDataReceived;
            udpClient.BindSocket("4002");

            Task.Run(async() =>
            {
                await udpClient.Send(UdpClient.BROADCAST_ADDR, "4001", Encoding.UTF8.GetBytes("<Discover target=\"LogicBox\" />"));
                await Task.Delay(5000);

                udpClient.DataReceived -= SocketDataReceived;
                udpClient.Dispose();
                udpClient = null;
            });
        }
Exemplo n.º 4
0
        public void Connect(string host, int port = 3671)
        {
            _host = host;
            _port = port;

            _udpClient = new UdpClient();
            _udpClient.DataReceived += UdpClientDataReceived;
            _udpClient.BindSocket(port.ToString());
            _udpClient.Connect(new HostName(host), port.ToString());

            _isConnected = true;

            this.SendConnectRequest();

            // enable state requests, if connected
            Task.Run(async() => {
                while (_isConnected)
                {
                    await Task.Delay(30000);
                    this.SendStateRequest();
                }
            });
        }