Issues with socket library after updating corona enterprise

Since updating my Corona Enterprise to 2016.2886 from 2015.2625, network communication using the socket library has been failing.  I have also tried with 2016.2904 and 2016.2906.

What we do is multicast over a port range that our servers could be listening for over a local network.  We do not get any errors outputting automatically about this, it just fails to communicate with anything.  Our server does not receive any messages while the app is broadcasting.

The only sort of error we get back is the remoteIP returned by udpsock:receivefrom(…) is “ai_family is not supported.”

Here is a snippet showing a boiled-down version of how we use it:

local Socket = require("socket") local udpsock = Socket.udp() udpsock:setoption("broadcast", true) udpsock:setoption("ip-multicast-loop", true) udpsock:setoption("ip-multicast-ttl", 100) udpsock:settimeout(0) local data = nil local remoteIP local port local ip = "192.168.0.1" -- we have a specific IPv4 address that our servers subscribe to for multicast local startTime = os.clock() -- scan all dynamic ports for available services on our network for portNum=65000,65535, 1 do udpsock:sendto("test me "..ip, ip, portNum) end data,remoteIP,port = udpsock:receivefrom(512) -- result: data = nil, remoteIP = "ai\_family is not supported", port = nil local elapsedTime = 0 while(elapsedTime \< 5) do if(data and data == whatWeExpectFromOurServer) then -- this is the server we will use break end data,remoteIP,port = udpsock:receivefrom(512) -- result: data = nil, remoteIP = "ai\_family is not supported", port = nil elapsedTime = os.clock() - startTime end udpsock:close() -- set the ip of the server we will use and attempt to establish a session

Thoughts on what might be going on would be greatly appreciated.

Starting with 2883, we switched from LuaSockets 2 to LuaSockets 3.0 rc-1.

This move was two fold: 1. Apple requires all apps submitted after June 1, 2016 to be fully functional on IPv6. (https://coronalabs.com/blog/2016/05/27/apple-ios-and-the-ipv6-deadline/). 2. Google Play didn’t like the version of OpenSSL we were using. The newer version required updating to LuaSockets 3. 

Of course we got a bunch of bug fixes in the process. You’re likely getting caught up in using a socket feature that was “fixed” in 3.0. I would suggest googling for the Lua Sockets 3 release notes and see if there is anything around the issues you’re encountering. You also might want to review their documentation on the various socket API calls you’re making since they may have changed something in the way a particular API works.

Rob

As Rob has said above, the LuaSocket library was updated for IPv6 support.
First, try setting the following option.  This is in case Android defaults this to true.  This way the UDP port will support IPv6 and IPv4 networks at the same time.

udpsock:setoption("ipv6-v6only", false)

If the above fails, then you can force it to be IPv4 only like how it was before by doing the following function call…

local Socket = require("socket") -- This tries to support IPv6 and IPv4. -- If this is not working for you, then leave this commented out for now. --local udpsock = Socket.udp() -- This only supports IPv4, like how LuaSockets used to work. -- Just don't do this on iOS. Apple will reject apps that are IPv4 only. local udpsock = Socket.udp4()

Thank you for the replies Rob and Joshua!  They were very helpful!

I managed to locate the LuaSocket v 3.0 documentation at https://rawgit.com/diegonehab/luasocket/master/doc/index.html. While I was inspecting the docs, I came across udp(), udp4(), and udp6().  Per the docs on udp():

Note: The choice between IPv4 and IPv6 happens during a call to sendtosetpeername, or sockname, depending on the address family obtained from the resolver.

Note: Before the choice between IPv4 and IPv6 happens, the internal socket object is invalid and therefore setoption will fail.

This explains the inability to communicate and error I receiving in remoteIP because none of my setoptions were applied the the udp socket!

So, the fix is to use Socket.udp4() or Socket.udp6() depending on the IP type, or to use Socket.udp() and call one of the methods noted above to have it choose the appropriate type for you.  I have currently opted to use Socket.udp4() and all has been working just fine!

Again, thank you very much for the assistance!  :slight_smile:

Starting with 2883, we switched from LuaSockets 2 to LuaSockets 3.0 rc-1.

This move was two fold: 1. Apple requires all apps submitted after June 1, 2016 to be fully functional on IPv6. (https://coronalabs.com/blog/2016/05/27/apple-ios-and-the-ipv6-deadline/). 2. Google Play didn’t like the version of OpenSSL we were using. The newer version required updating to LuaSockets 3. 

Of course we got a bunch of bug fixes in the process. You’re likely getting caught up in using a socket feature that was “fixed” in 3.0. I would suggest googling for the Lua Sockets 3 release notes and see if there is anything around the issues you’re encountering. You also might want to review their documentation on the various socket API calls you’re making since they may have changed something in the way a particular API works.

Rob

As Rob has said above, the LuaSocket library was updated for IPv6 support.
First, try setting the following option.  This is in case Android defaults this to true.  This way the UDP port will support IPv6 and IPv4 networks at the same time.

udpsock:setoption("ipv6-v6only", false)

If the above fails, then you can force it to be IPv4 only like how it was before by doing the following function call…

local Socket = require("socket") -- This tries to support IPv6 and IPv4. -- If this is not working for you, then leave this commented out for now. --local udpsock = Socket.udp() -- This only supports IPv4, like how LuaSockets used to work. -- Just don't do this on iOS. Apple will reject apps that are IPv4 only. local udpsock = Socket.udp4()

Thank you for the replies Rob and Joshua!  They were very helpful!

I managed to locate the LuaSocket v 3.0 documentation at https://rawgit.com/diegonehab/luasocket/master/doc/index.html. While I was inspecting the docs, I came across udp(), udp4(), and udp6().  Per the docs on udp():

Note: The choice between IPv4 and IPv6 happens during a call to sendtosetpeername, or sockname, depending on the address family obtained from the resolver.

Note: Before the choice between IPv4 and IPv6 happens, the internal socket object is invalid and therefore setoption will fail.

This explains the inability to communicate and error I receiving in remoteIP because none of my setoptions were applied the the udp socket!

So, the fix is to use Socket.udp4() or Socket.udp6() depending on the IP type, or to use Socket.udp() and call one of the methods noted above to have it choose the appropriate type for you.  I have currently opted to use Socket.udp4() and all has been working just fine!

Again, thank you very much for the assistance!  :slight_smile: