Beispiel #1
0
 /// <summary>
 /// Sends data asynchronously to a connected OpenWiz.WizSocket.
 /// </summary>
 /// <param name="s">The data to send.</param>
 /// <param name="handle">The handle to the remote light.</param>
 /// <param name="callback">The System.AsyncCallback delegate to fall after the send completes.</param>
 /// <param name="state">An object that will be passed into the callback.</param>
 /// <exception cref="System.ArgumentNullException">
 /// s is null.
 /// </exception>
 /// <exception cref="System.Net.Sockets.SocketException">
 /// An error occurred when attempting to access the underlying socket.
 /// </exception>
 /// <exception cref="System.ObjectDisposedException">
 /// The underlying socket has been closed.
 /// </exception>
 /// <returns>An System.IAsyncResult that references the asynchronous send.</returns>
 ///
 public IAsyncResult BeginSend(WizState s, WizHandle handle, AsyncCallback callback, object state)
 {
     byte[] buffer = s.ToUTF8();
     return(socket.BeginSendTo(buffer, 0, buffer.Length, SocketFlags.None,
                               new IPEndPoint(handle.Ip, PORT_DISCOVER),
                               callback, state));
 }
        /// <summary>
        /// Constructs the service, targeting the a specific home of lights.
        /// </summary>
        /// <param name="homeId">The Home ID to which the user's lights belong</param>
        /// <param name="hostIp">The IPv4 of the host machine, in standard dot notation</param>
        /// <param name="hostMac">The MAC of the host machine's interface card, 6 bytes wide</param>
        ///
        public WizDiscoveryService(int homeId, string hostIp, byte[] hostMac)
        {
            WizState registrationData = WizState.MakeRegistration(homeId, hostIp, hostMac);

            Debug.WriteLine($"[INFO] WizDiscoveryService@{hostIp}: Made registration info: {registrationData}");
            pingData    = registrationData.ToUTF8();
            this.hostIp = hostIp;
            KeepAlive   = false;
        }
Beispiel #3
0
        /// <summary>
        /// Sends data to a connected OpenWiz.WizSocket.
        /// </summary>
        /// <param name="s">A OpenWiz.WizState containing the data to be sent.</param>
        /// <param name="handle">The handle to the remote light.</param>
        /// <exception cref="System.ArgumentNullException">
        /// s or handle are null.
        /// </exception>
        /// <exception cref="System.Net.Sockets.SocketException">
        /// An error occurred when attempting to access the underlying socket.
        /// </exception>
        /// <exception cref="System.ObjectDisposedException">
        /// The underlying socket has been disposed.
        /// </exception>
        /// <returns>the number of bytes sent</returns>
        ///
        public int SendTo(WizState s, WizHandle handle)
        {
            if (s == null)
            {
                throw new ArgumentNullException("s cannot be null");
            }
            if (handle == null)
            {
                throw new ArgumentNullException("handle cannot be null");
            }

            byte[] bytes = s.ToUTF8();
            return(socket.SendTo(bytes, new IPEndPoint(handle.Ip, PORT_DISCOVER)));
        }