gilmaimon / ArduinoWebsockets

A library for writing modern websockets applications with Arduino (ESP8266 and ESP32)
GNU General Public License v3.0
482 stars 97 forks source link

Which syntax to use for esp to esp contact when using mDNS ? #77

Closed denden4444 closed 4 years ago

denden4444 commented 4 years ago

Hi Gil

How are you ? (keeping safe I hope ..long time no speak to)

Your websockets library has been working in tests so far. I can say it's very responsive :-) Thank you for your awesome efforts and the code and ability to use it.

I would like to know which syntax to use when connecting from ESP8266 to ESP 8266 when using mDNS. Here's what I'm trying (using part ESP8266 core) : 1.Trying to use the mDNS name of the Websockets server listening on port 81 (instead of using the IP address which works perfectly) I have the mDNS hostname and then append and prepend using sscanf like this:

char name[20]="anyNameIfeedIn";
sprintf(websockets_server_host,"%s%s%s%s ","http://",name,".local",":81");

Which ends up as http://anyNameIfeedIn.local:81 But this sadly doesn't connect :-( I have also tried : anyNameIfeedIn.local:81 and anyNameIfeedIn.local as well as http://anyNameIfeedIn.local:81.

If i use this address (http://anyNameIfeedIn.local:81) from my browser test program I can successfully connect to the server.

If I use an IP address in this field : websockets_server_host Then it works perfectly !

I have also used and tried (ws) ws://anyNameIfeedIn.local:81with the various combinations as above and the same occurs.

Could you please possibly shed some light ? Was there a bug in some older version of the library which I am possibly still using ?

And one more question : Is there a timeout that can be set (possibly for trouble-shooting) which governs the wait time when websocket client tries to connect ?

bool connected = clientB.connect(websockets_server_host, websockets_server_port, "/");

Kind regards

Den

gilmaimon commented 4 years ago

Hi Den.

I'll start from the bottom, there is no timeout feature implemented currently. Under-the-hood this is just a WiFiClient so you could try to dig in and add this code yourself (either in some generic way, or just ad-hoc for your issue)

Regarding the .local suffix, I am not very familiar with mDNS but I read here that the local suffix has some unique properties? And it should be resolved by a mDNS code rather than by the esp8266 libraries themself?

See if you can somehow resolve the IP using mdns and then pass it over to the websocket client.

Gil.

denden4444 commented 4 years ago

Hi Gil (Hope this reply finds you well)

Thanks a million for the reply. Ok re time-out :-( .. May I add it to the "wish-list":-) ?

Cool re .local and mDNS ..Thanks will continue my investigation and pingback with update(s).

So without any of the above have you tried your webSockets (client to server) from ESP to ESP using HOSTNAME not IP yet ? If so, does it work and were you successful ?

Kind regards

Den

gilmaimon commented 4 years ago

I haven't tried something like that yet. I assume it will work, as it depends on underlying WiFiClient provided by the esp8266/esp32 libraries.

I could add it to a wish-list, but it is meaningless because:

  1. As an only maintainer, I don't have enough time to enhance the library. I mainly focus on maintaining it working and helping with usage issues
  2. It will probably require either some low level mdns impl or require mdns library as dependency. Both are stuff I really don't want to get into, so it won't happen.

Gil.