Name resolving of TCPClient when connecting to other Photon running mDNS


In order to make two Photons in the same local WiFi to connect I concluded that there is no other way than TCP or UDP connection (no WiFi direct yet Sample Code for Connecting 2 Photons (Wifi Direct)). At the same time I would like to have it dynamic i.e I do not want to hardcode any static IP since different WiFi networks can have different setups and it may result in a conflict.

  1. I found mDNS solution which works fine, I can ping the device and make a request at the ports 80 and 8080 using defined URL.

  2. I wanted to integrate same functionality to another Photon using TCPClient (Thanks for the ideas from the threads TCPServer() usage and bandwidth issue and Sending large data off Photon using TCPClient). The problem I stumbled upon is that the API from TCPClient

    virtual int connect(const char *host, uint16_t port, network_interface_t=0);

Cannot succeed to connect when using URL (connect() returns -4). When I use the manual IP address it connects fine

virtual int connect(IPAddress ip, uint16_t port, network_interface_t=0);

Is it possible at all using URL to connect to another Photon which is running the self-assembled mDNS? Should I need to implement some kind of address resolving inside the code or trigger some DNS cache functionality?

I wasn’t able to find an mdns client for the Photon. And it adds quite a bit of unnecessary complexity for Photon-to-Photon communication over a local network.

I created two sets of sample programs for locating the IP address of a Photon so you can do client-server communications with it, without having to hard-code IP addresses.

One uses publish and subscribe. It’s easy and relatively secure.

The second uses multicast UDP. This technique works well if you don’t have Internet or cloud access.

Code and further explanation are here:


Thanks, the multicast approach works currently :smile:
I am still using AUTOMATIC mode though… But it worked in manual too.
Great job…

1 Like