AutoLan + IPv6

RESOLVED:  http://github.com/roaminggamer/AutoLan-IPv6/

Issue

As of Corona 2016.2883, AutoLan broadcasts fail.

Cause

  • Corona 2016.2883 and beyond use Lua Sockets 3.0rc1. 
  • AutoLan uses ‘Broadcast’ mechanism which is not supported (as coded) in this version or Lua Sockets.

What I’m Doing

I am debugging (very quiet) failure and ‘trying’ fix this on my own.  However, this is an area that I am weak in. 

So…

What I Need

I’ve searched the web and this site, as well as talked to some folks about this.  I have leads, but am hoping someone has already fixed this (call me lazy).

In particular, I saw this thread: https://forums.coronalabs.com/topic/58394-got-old-auto-lan-to-work/

** UPDATE ** This part figured out, now on to converting broadcast to multicast.

However, the code link is dead AND ‘scottrules44’ (are you reading this?) didn’t specify the files or lines he changed so I’m currently hunting and pecking.

In short… If you have any idea how to get the old AutoLan auto-discovery feature working, please post back.

Otherwise, assuming I figure it out, I’ll post a solution later.

Thanks,

Ed

PS - Yes, I did notice the reference to ‘socket.dns.toip’ and that is where I’m starting, but it is used in four places and I’m unclear (as yet) on the best values to use in the new code to make this durable and safe.  Reading… :slight_smile:

Current Progress

I figured out what lines of code Scott changed (pretty sure here) and modified them.

Note: This code is actually functional across both sockets 2 and 3 so that is very nice.

Next

Now I have to figure out how to recode the IPv4 ‘Broadcast’ code as ‘Multicast’ code (hopefully compliant w/ both IPv6 and IPv4.

Implications of the Changes to Address Types in IPv6

Broadcast addressing as a distinct addressing method is gone in IPv6. Broadcast functionality is implemented using multicast addressing to groups of devices. A multicast group to which all nodes belong can be used for broadcasting in a network, for example.

from:

http://www.tcpipguide.com/free/t_IPv6AddressingOverviewAddressingModelandAddressTyp-2.htm

Again, anyone with clues… I need em.

Thanks again,

Ed

PS - I’ll post all my changes when I’m done.

Ed,

As you’ve seen, the LuaSockets library was updated to version 3 which adds IPv6 support.  The one breaking change it has is that you can’t call setoption() on a TCP or UDP socket that was created by a socket.tcp() or socket.udp() call until **AFTER** you open the socket connection via a call to connect(), bind(), sendto(), setpeername(), or sockname().  This is because LuaSockets does not make the determination on whether to connect via IPv4 or IPv6 until after those connection calls.

Also note that LuaSockets adds the following new APIs:

  • socket.udp4()  – Creates an IPv4 only UDP socket
  • socket.udp6()  – Creates an IPv6 only UDP socket
  • socket.tcp4()  – Creates an IPv4 only TCP socket
  • socket.tcp6()  – Creates an IPv6 only TCP socket

The above will immediately create a valid socket where you **CAN** call setoption() on them immediately afterwards.  And if you want LuaSockets old version 2 behavior, then you should call socket.udp4() and socket.tcp4() instead, but just note that Apple will rejects apps that do this on iOS.

Here is a link to the updated LuaSocket version 3 API documentation…

   https://rawgit.com/diegonehab/luasocket/master/doc/reference.html

And you can also see another LuaSocket v3 UDP discussion I’ve had with an Enterprise developer in the link below, if you think it’ll help you any.

   https://forums.coronalabs.com/topic/63755-issues-with-socket-library-after-updating-corona-enterprise/?p=330816

I hope this helps!

@Joshua,

Thanks for the response.  I’ve read it once and will re-read it again later when my brain is ‘fresher’.  

Meanwhile, if you and others wonder why this came up…

I have a private tool I simply call ‘Reflector’.  This tool allows me to send any Runtime event from one device to another.  I use this to:

  • Send Apple TV remote inputs to the simulator (no need to install, fix, re-isntall, … just fix, reload simulator, wait for attach, test changes)
  • Send Phone/Tablet device inputs to simulator.  Same deal.
  • Same as above with the addition of requesting specific input types such as:
    • Virtual Joystick
    • One Touch
    • Two Touch
    • Joystick on left and touch on right

This video shows the latter in action:

https://www.youtube.com/watch?v=CAmNnomqPWQ

As you can see, I’m actually running two copies of the simulator, but that is to make this video.  The major elements in this video are:

  • Simulator on upper-left --> work in progress app on the simulator.

  • Simulator on upper-right --> This would normally be running on a device.  Write the app once, install once, run and it auto-configures on each reload of app in progress.

  • Code window at bottom - So you can see, it takes one line of code to request specific input events and optionally a input setup.

    – Asks ‘reflector’ device to send custom ‘onJoystick’ and ‘onOneTouch’ events – also asks it to build a special input with joystick on left and touch ‘pad’ on right receiver.init( { “onJoystick”, “onOneTouch”, “easyInput_oneStickOneTouch” } ) – asks for standard events: “key”, “axis”, “accelerometer”, – plus custom event ‘onDied’ receiver.init( { “key”, “axis”, “accelerometer”, “onDied” } )

Scott here let me take a look

Edit: here is link

https://www.dropbox.com/s/4nni4s085ofhg3y/pong%20demo.zip?dl=0

I am a bit slow having some device problem (water proof case did not work as aspected). I have been using the plugin above for about a year and have not run to any problems but of course have published it to apple.

In case that link does not still work I have it attached

Scott,

I downloaded your Pong Demo project.  As a quick solution, I got it working by replacing all calls to…

   socket.udp()

…with…

   socket.udp4()

After doing that, the game could be played in multiplayer.  And for your info, I tested it on Windows by running 2 Corona Simulator instances.

So, the next step would be to add support for IPv6 networks.

Ok I will take a look, it work on device without changes, but I will make the updates Joshua suggested.

Thanks,

Scott

Ok done

https://www.dropbox.com/s/scov9chhm917pxu/pong%20demo%20ipv6.zip?dl=0

Edit : I wast trying to update the forum post to add this link but it say it has been archived

Edit2: Let me know of any problems just got it works

One more thing. I’ve noticed that the “Client.lua” and “Server.lua” files both call socket.tcp() as well.
​If we’re going to hardcode it to IPv4 for the moment, then that should be changed to socket.tcp4() as well.

I’m not sure why that didn’t cause a problem for me though. But admittedly, I didn’t take a hard look at the code.  I just did a simple find/replace in the code and tested it out.

Wait should it be socket.tcp6 for IPv6

Calling socket.tcp6() would force that socket to communicate via IPv6 only, which is probably NOT what you want.  Especially since most home users don’t have an IPv6 LAN set up.

As a quick fix, changing all calls to socket.udp() to socket.udp4() and socket.tcp() to socket.tcp4() will restore the old LuaSocket behavior.

Ok I was just thinking of the apple requirements for ipv6 but that does not apply to ipv4 lan (right?). Sorry, I have not read all apple’s new requirements

https://www.dropbox.com/s/b2jcjvferki57fg/pong%20demo%202.zip?dl=0

Apple wants apps to support both IPv6 and IPv4 networks.

For client connections, they expect your app to favor IPv6 if available, but it’s not, then it should fallback to IPv4.

The code changes I’ve suggested up above would be rejected by Apple because it forces AutoLAN to support IPv4 only networks, which is how it used to work before.  I was just trying to help you guys in getting it working again.  The next step would be to *add* both IPv6 and IPv4 support to the AutoLAN library.  I’m pretty sure code changes are required to do so.

Ok made some changes.

https://www.dropbox.com/s/b2jcjvferki57fg/pong%20demo%203.zip?dl=0

Wow!  My Wife and I won second place at the golf tournament and you guys worked like fiends on this!

I think this means whenever I get stuck in the future I should ask a question and then go golfing! :slight_smile:

Really though, thanks to you each for work on this while I was absent.   I’m going to work my way though the discussion and try the linked zip(s).

Thanks again.

Fore!

PS - For context, Scott sent me an email yesterday as I was walking out the door for a tournament and I apologized for having to me gone.  So, while he knows what I’m talking about… I thought I ought to explain. 

I threw away the old ones from my dropbox the latest one should still work
Edit: Ed congrats on golf tournament. I don’t have a IPv6 network so can not test this, but it “should” work if you have a IPv6 network

** MARKED THIS POST AS SOLVED TO GET LINK TO REPOSITORY AT TOP **

** NOT TO GIVE SELF CREDIT **

** KUDOS TO ALL WHO HELPED AND WORKED ON THIS **

OK.  I’ve played around with this and made some further improvements.

Now, the library is backward and forward compatible.  It (should) work for socket2/socket3 and all versions of Corona.

I’ve tested this on several devices and it all looks solid.

You can find the updated libraries and sample pong game here (with credits and thanks):

http://github.com/roaminggamer/AutoLan-IPv6/

Note: While you should not need it, if you are running 2016.2883 or later, and if you want to force the modules to use IPV4, simply locate this variable in server.lua and client.lua and set it to true:

local forceIPV4 = true

Nice job!

That example uses graphics 1.0 so I downloaded your pong demo and made some changes to make it work with graphics 2.0 to make the demo last longer.

Edit: I remember you corona geek talk about your remote idea for Apple TV. Hope it works out. I have been thinking about how it could be done with the autolan, but it is easy to filter search by device type (like Apple TV). Plus I their is some code to send files over wifi.