Zero-conf Multi Player

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:

  1. Activate zero-conf: https://marketplace.coronalabs.com/plugin/zeroconf

  2. Copy the folder “zeroconf_mp” and file “zeroconf_mp.lua” to your local project.

  3. Reference the file:

    local multiplayer = require(“zeroconf_mp”)

  4. 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. )

  5. 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”

  6. To send data call this function:

    multiplayer.sendData(testData) – Table of data to send.

  7. To clean things after the game is over:

    multiplayer.endGame() 

Some notes:

  1. 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.

  2. Only tested with 2 devices but should work with more.

  3. 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.

Just curious to why my name is part of the project name. All I did was publish the guest post. Perhaps its best to rename it without my name in the title.

Rob

Sorry Rob. I’ll do that. I thought you had written it. I’ll change the name soon. The post had your name on the byline and I never thought to check up on it or read the intro until just today. I am also not very creative with names.

You name has been removed. Sorry again.

This is GREAT  :smiley:

Thanks a lot for sharing @agramonte

Hey How can I test it, I used the emulator as the server, and the cliente from my phone. but couldnt see no results

I got this error

WARNING: C:\Users\Willy\Desktop\zcrmmp-master\zeroconf_mp.lua:71: zeroconf.publish(): failed to create service!

and also I run your project in 2 devices and click on start game but nothing happens it appears the Looking text.

What were the two devices? Android or iOS?

How about your machine? Is it a Mac or a Windows machine?

Just curious to why my name is part of the project name. All I did was publish the guest post. Perhaps its best to rename it without my name in the title.

Rob

Sorry Rob. I’ll do that. I thought you had written it. I’ll change the name soon. The post had your name on the byline and I never thought to check up on it or read the intro until just today. I am also not very creative with names.

You name has been removed. Sorry again.

This is GREAT  :smiley:

Thanks a lot for sharing @agramonte

Hey How can I test it, I used the emulator as the server, and the cliente from my phone. but couldnt see no results

I got this error

WARNING: C:\Users\Willy\Desktop\zcrmmp-master\zeroconf_mp.lua:71: zeroconf.publish(): failed to create service!

and also I run your project in 2 devices and click on start game but nothing happens it appears the Looking text.

What were the two devices? Android or iOS?

How about your machine? Is it a Mac or a Windows machine?