Enable Multiplayer Networking with your Mobile Games with 3 functions.
Click here to visit Corona SDK Website:
Download Source Code here: https://github.com/pubnub/pubnub-api/tree/master/lua-corona
Follow these easy steps to get starting with your Multiplayer API.
http://www.pubnub.com/account#api-keys
http://www.pubnub.com PubNub is a new kind of Cloud-Hosted Broadcasting Service for Mass Communication on Mobile Phones, Tablets, TVs, HTML5 Web Browsers and Game Consoles. Already more messages are published to PubNub each day than to Twitter. We believe in unified broadcasting and mass communication empowerment for application and game developers who build on Mobile Phones, TVs, HTML5 Web Browsers, Tablets and Game Consoles.
1 2 3 4 5 6 7 8 9 10 11 12 13 | require "pubnub" -- -- GET YOUR PUBNUB KEYS HERE: -- http://www.pubnub.com/account#api-keys -- multiplayer = pubnub.new({ publish_key = "demo", -- YOUR PUBLISH KEY subscribe_key = "demo", -- YOUR SUBSCRIBE KEY secret_key = nil, -- YOUR SECRET KEY ssl = nil, -- ENABLE SSL? origin = "pubsub.pubnub.com" -- PUBNUB CLOUD ORIGIN }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 | -- -- PUBNUB SUBSCRIBE CHANNEL (RECEIVE MESSAGES) -- multiplayer:subscribe({ channel = "lua-corona-demo-channel", callback = function(message) -- MESSAGE RECEIVED!!! print(message) end, errorback = function() print("Network Connection Lost") end }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | -- -- PUBNUB PUBLISH MESSAGE (SEND A MESSAGE) -- multiplayer:publish({ channel = "lua-corona-demo-channel", message = { "1234", 2, 3, 4 }, callback = function(info) -- WAS MESSAGE DELIVERED? if info[1] then print("MESSAGE DELIVERED SUCCESSFULLY!") else print("MESSAGE FAILED BECAUSE -> " .. info[2]) end end }) |
1 2 3 4 5 6 | -- -- PUBNUB UN-SUBSCRIBE CHANNEL (STOP RECEIVING MESSAGES) -- multiplayer:unsubscribe({ channel = "lua-corona-demo-channel" }) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | -- -- PUBNUB LOAD MESSAGE HISTORY -- multiplayer:history({ channel = "lua-corona-demo-channel", limit = 10, callback = function(messages) if not messages then return print("ERROR LOADING HISTORY") end -- NO HISTORY? if not (#messages > 0) then return print("NO HISTORY YET") end -- LOOP THROUGH MESSAGE HISTORY for i, message in ipairs(messages) do print(Json.Encode(message)) end end }) |
1 2 3 4 5 6 7 8 9 | -- -- PUBNUB SERVER TIME -- multiplayer:time({ callback = function(time) -- PRINT TIME print("PUBNUB SERVER TIME: " .. time) end }) |