I have a problem with a plugin zeroconf

Hello,

 

I have a problem with using plugin zeroconf, I just copied the code from the example from Corona documentation and put it on the simulator, but it gives me an warning alert : “failed to create service!”. 

I send you two pictures to see what the problem is.

I’m developing an application and want to exchange data between two devices on the LAN network.

Please give advice on how to communicate between the two devices (both use Android) using plugin zeroconf .

 

Thanks in advance for your cooperation.

 

Sincerely,

Emanuel

 

I need to read the documentation carefully. 

I had missed the warning that plugin zeroconf works on all platforms except Windows ( I use Windows 8.1 ). 

I installed Bonjour SDK and the error message did not appear. 

I will try to make a working example with zeroconf and publish the code for discussion.

Hello friends,

I decided to read the zeroconf plugin documentation again and found a solution to my problem.

I promised to try to make working examples of using zeroconf plugin to send and receive data.

Here is the code for the examples.

If you want to see how they work, make two new projects with Corona Simulator and writing the Sender code in main.lua file and entering the Receiver code in the other in main.lua file.

Then start Sender first and then Receiver and you will see the result on the console.

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- ---- Sender local zeroconf = require( "plugin.zeroconf" ) local json = require( "json" ) local first = "Corona " local seccond = "is" local third = "awesome !" local record = {} record.first = first record.seccond = seccond record.third = third print( json.prettify( record ) ) -- Publishes a service of type '\_corona\_test.\_tcp' -- Listener to be called for ZeroConf events local function zeroconfListener( event ) -- Service has been found if ( event.phase == "found" and not event.isError ) then print( "SERVICE FOUND" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end if event.port then print( "Port: " .. tostring(event.port) ) end if ( event.addresses and #event.addresses \> 0 ) then print( "Service provider addresses:" ) for i = 1,#event.addresses do print( " " .. event.addresses[i] ) end end -- Service has been lost! elseif event.phase == "lost" then print( "SERVICE LOST!" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end end end -- Initialize listener zeroconf.init( zeroconfListener ) -- Generate a service name local serviceName = system.getInfo("name") .. " (" .. system.getInfo("platformName") .. ")" -- Publish a service (make it discoverable over the network) local service = zeroconf.publish( { port=2929, name=serviceName, type="\_corona\_test.\_tcp", data=record } ) 

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- ---- Receiver local zeroconf = require( "plugin.zeroconf" ) local json = require( "json" ) -- Publishes a service of type '\_corona\_test.\_tcp' and then starts discovery for the service -- Listener to be called for ZeroConf events local function zeroconfListener( event ) -- Service has been found if ( event.phase == "found" and not event.isError ) then print( "SERVICE FOUND" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end if event.port then print( "Port: " .. tostring(event.port) ) end if ( event.addresses and #event.addresses \> 0 ) then print( "Service provider addresses:" ) for i = 1,#event.addresses do print( " " .. event.addresses[i] ) end end if event.data then local ed = event.data print( json.prettify( ed ) ) end -- Service has been lost! elseif event.phase == "lost" then print( "SERVICE LOST!" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end end end -- Initialize listener zeroconf.init( zeroconfListener ) -- Start looking for published services local browser = zeroconf.browse( { type="\_corona\_test.\_tcp" } ) --------------------------------------------------------------------

It’s okay when this plugin ( zeroconf ) is implemented and applications run in two Corona simulators. 

Data is sent and received.

But when applications are installed on real Android devices, they do not exchange information.

Can any of the forum members help me because I can’t handle it myself.

I need to read the documentation carefully. 

I had missed the warning that plugin zeroconf works on all platforms except Windows ( I use Windows 8.1 ). 

I installed Bonjour SDK and the error message did not appear. 

I will try to make a working example with zeroconf and publish the code for discussion.

Hello friends,

I decided to read the zeroconf plugin documentation again and found a solution to my problem.

I promised to try to make working examples of using zeroconf plugin to send and receive data.

Here is the code for the examples.

If you want to see how they work, make two new projects with Corona Simulator and writing the Sender code in main.lua file and entering the Receiver code in the other in main.lua file.

Then start Sender first and then Receiver and you will see the result on the console.

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- ---- Sender local zeroconf = require( "plugin.zeroconf" ) local json = require( "json" ) local first = "Corona " local seccond = "is" local third = "awesome !" local record = {} record.first = first record.seccond = seccond record.third = third print( json.prettify( record ) ) -- Publishes a service of type '\_corona\_test.\_tcp' -- Listener to be called for ZeroConf events local function zeroconfListener( event ) -- Service has been found if ( event.phase == "found" and not event.isError ) then print( "SERVICE FOUND" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end if event.port then print( "Port: " .. tostring(event.port) ) end if ( event.addresses and #event.addresses \> 0 ) then print( "Service provider addresses:" ) for i = 1,#event.addresses do print( " " .. event.addresses[i] ) end end -- Service has been lost! elseif event.phase == "lost" then print( "SERVICE LOST!" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end end end -- Initialize listener zeroconf.init( zeroconfListener ) -- Generate a service name local serviceName = system.getInfo("name") .. " (" .. system.getInfo("platformName") .. ")" -- Publish a service (make it discoverable over the network) local service = zeroconf.publish( { port=2929, name=serviceName, type="\_corona\_test.\_tcp", data=record } ) 

----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- ---- Receiver local zeroconf = require( "plugin.zeroconf" ) local json = require( "json" ) -- Publishes a service of type '\_corona\_test.\_tcp' and then starts discovery for the service -- Listener to be called for ZeroConf events local function zeroconfListener( event ) -- Service has been found if ( event.phase == "found" and not event.isError ) then print( "SERVICE FOUND" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end if event.port then print( "Port: " .. tostring(event.port) ) end if ( event.addresses and #event.addresses \> 0 ) then print( "Service provider addresses:" ) for i = 1,#event.addresses do print( " " .. event.addresses[i] ) end end if event.data then local ed = event.data print( json.prettify( ed ) ) end -- Service has been lost! elseif event.phase == "lost" then print( "SERVICE LOST!" ) print( "-------------" ) if event.serviceName then print( "Service name: " .. event.serviceName ) end end end -- Initialize listener zeroconf.init( zeroconfListener ) -- Start looking for published services local browser = zeroconf.browse( { type="\_corona\_test.\_tcp" } ) --------------------------------------------------------------------

It’s okay when this plugin ( zeroconf ) is implemented and applications run in two Corona simulators. 

Data is sent and received.

But when applications are installed on real Android devices, they do not exchange information.

Can any of the forum members help me because I can’t handle it myself.