As most know CoronaLabs released the Zero-conf extension a few weeks ago:
https://docs.coronalabs.com/plugin/zeroconf/index.html
What most people don’t remember is that Rob Miracle published a great tutorial back in 2014 on how to use UDP/TCP to create a local multiplayer server (Original tutorial was written by Mark Steelman):
https://coronalabs.com/blog/2014/09/23/tutorial-local-multiplayer-with-udptcp/
The UDP portion of this tutorial never worked for me so when zeroconf was released, I wonder if I could make the TCP portion of that tutorial work with zeroconf.
I have created a simple lua library that does just that and plan to use it for some of my games. Although it still needs some work it might be good enough now for other people to play with it if they want or need it.
It can be found on github:
https://github.com/agramonte/zcrmmp
How to use:
-
Activate zero-conf: https://marketplace.coronalabs.com/plugin/zeroconf
-
Copy the folder “zeroconf_mp” and file “zeroconf_mp.lua” to your local project.
-
Reference the file:
local multiplayer = require(“zeroconf_mp”)
-
Init the library:
local properties = {} properties.gameName = “TestGame” – Game Name. properties.serverName = “TestServer” – Server Name. properties.searchForLength = 2000 – Miliseconds to search for server before starting one. properties.numberOfPlayers = 2 – Total number of players. multiplayer.init( onMultiplayerEvent, – Event for callback. properties – Table just created above with the options. )
-
Listen to possible callbacks:
When the client or server recieves data from another client. eventData.name = “zeroconf_mp” eventData.phase = “dataRecieved” eventData.isError = “false” eventData.data = <table with the data recieved> When a client connects to the server. Server only event. eventData.name = “zeroconf_mp” eventData.phase = “playerAdded” eventData.isError = “false” eventData.data = <table of players> When a client connects to the server. Client only event. eventData.name = “zeroconf_mp” eventData.phase = “connected” eventData.isError = “false”
-
To send data call this function:
multiplayer.sendData(testData) – Table of data to send.
-
To clean things after the game is over:
multiplayer.endGame()
Some notes:
-
Only tested on Android devices and my Macbook. iOS testing is next on my list, not sure if I’ll ever test it on Windows.
-
Only tested with 2 devices but should work with more.
-
There is a very simple example app that you can compile (it also will run in the emulator for one of the client/servers) and run on 2 devices to play with. It requires that you activate toast here: https://marketplace.coronalabs.com/plugin/toast.