Can't create a UDP Socket and Multicast Socket
Posted: Fri Apr 24, 2015 6:34 pm
I need to have two listening sockets (Contexts in Esp8266/Arduino speak) for my CoapServer. One for the Multicast and one for a unicast. They both use the same port by CoAp standards.
Which ever one is created first succeeds, but the second one created fails in UdpContext::Listen. The call to udp_bind within UdpContext::Listen returns error code is ERR_USE; meaning the address is in use?
Coap Port is 5684
Coap Multicast Address is 224.0.1.187
By normal socket concepts this should be doable, not so sure by Esp8266 context concepts.
Further, if I just create a multicast socket, while it will receive multicast packets, it will not receive packets sent directly to the ipaddress of the device. This works as I would expect IF I can create the two functional sockets.
here are snippits of the code, just for completeness, they work independently but not when called back to back.
multicast
unicast
Which ever one is created first succeeds, but the second one created fails in UdpContext::Listen. The call to udp_bind within UdpContext::Listen returns error code is ERR_USE; meaning the address is in use?
Coap Port is 5684
Coap Multicast Address is 224.0.1.187
By normal socket concepts this should be doable, not so sure by Esp8266 context concepts.
Further, if I just create a multicast socket, while it will receive multicast packets, it will not receive packets sent directly to the ipaddress of the device. This works as I would expect IF I can create the two functional sockets.
here are snippits of the code, just for completeness, they work independently but not when called back to back.
multicast
Code: Select all
multicastSocket = new WiFiUDP();
if (!multicastSocket ->beginMulticast(WiFi.localIP(),
IPAddress(CoapMultiCastAddress) ,
CoapPort))
{
// error
}
unicast
Code: Select all
unicastSocket = new WiFiUDP();
// unicast
if (!unicastSocket->begin(CoapPort))
{
// error
}