Corona SDK Multiplayer Networking API for Mobile Games

Enable Multiplayer Networking with your Mobile Games with 3 functions.

  1. Init PubNub Multiplayer Object
  2. Call Subscribe() to begin receiving messages.
  3. Call Publish() to send messages.

Click here to visit Corona SDK Website:

Download Corona Multiplayer API

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.

  1. Download Lua Corona Multiplayer API
  2. Get Your PubNub Keys Here
  3. Copy the files into your Lua Code Directory
  4. Continue Reading to add just 3 functions to Enable Multiplayer Support.

Get Your PubNub Keys Here

http://www.pubnub.com/account#api-keys

Learn about PubNub Cloud-Hosted Service for Real-Time Messaging

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.


PubNub Creates Real-time Social Experiences

Initiate Multiplayer PubNub Object.

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 
})

Listen for Messages from Other Players.

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 
})

Send Message To Other Players.

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 
})

Stop Listening for Messages.

1
2
3
4
5
6
-- 
-- PUBNUB UN-SUBSCRIBE CHANNEL (STOP RECEIVING MESSAGES) 
-- 
multiplayer:unsubscribe({ 
    channel = "lua-corona-demo-channel" 
})


Multiplayer Netowrking Mobile Game Foundation for Corona SDK

Load Message History

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 
})

Get PubNub Server Time

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 
})


PubNub High Scale Cloud-Hosted Real-time Messaging Service