C++ GetService Broadcast Not Working

Working on putting together a C++ app that will control my lights via LAN API. However, upon broadcasting the packet out, I do not receive any responses from the lights (but I do receive my broadcasted packet).

Here’s a link to my source code: http://pastebin.com/YXb4N8Ve

Any thoughts on what’s going on?

Okay so you have two sockets, client_socket and server_socket. server_socket is listening on INADDR_ANY and port 56700 so it will receive all packets sent on the network to port 56700. client_socket is also listening on INADDR_ANY but it is listening on a free port chosen by the operating system.

When you send the packet you are setting the source field so the bulb will respond by setting the destination port and destination address to the source port and source address.

You send the packet out of the client_socket which means the packet will have a source address set to your IP, and the random port chosen by the OS. As such the bulb will respond to you, on that random port. This means that the packet will return to the client_socket and not the server_socket. You should try to receive your packets on the client_socket instead. You should be able to completely remove the server_socket.

Hope this helps! Let me know how it goes.

Okay I went through your example to try and get if going on my machine, and I found a few more issues …

  1. You are using the wrong header, not sure where you got yours but the correct one can be found at the bottom of the header description page in the official documentation.
  2. If you would like the bulb to respond you need to set either res_required or ack_required depending in the type of responses you would like.

I’m not great at C++ and don’t have Windows, so I altered your code to work in C on Linux and got it working. I’ve uploaded it to a gist for you.

Thanks @daniel_hall!!
I’ve spent a bit of time and put together lib-lifx, a C++14 LIFX library that’s open for everyone to use.

I welcome any feedback you and others may have.

Thanks again for your help!


Hi Daniel_hall,

I am new to LIFX LAN application development,(LIFX LAN API )

I want to write the C++ application for LIFX, I want to know is there any API by which I can get the IP address of LIFX device,

I am unable to get the IP address of LIFX device please do let me know the reference code or any reference doc.