Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Interacting Corona SDK app (LuaSocket) with my socket.io chat example server
Started by petiflas Dec 26 2013 03:20 PM

- - - - -
4 replies to this topic
socket.io socket websocket
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 5 posts
  • Corona SDK

I am writing an app for Corona SDK (Using LuaSocket) to be
able to subscribe and post messages to the example chat server that runs
in socket.io (using gevent-websocket 0.9).

I have checked that chat.js on the server interacts with ther server like this:

To subscribe to a room:


Or interacting with the chat room:

socket.send({room: 'room-2000', action: 'start', name: 'John'})

socket.send({room: 'room-2000', action: 'message', message: 'hi there!)});


Full js client script: https://bitbucket.org/stephenmcd/django-socketio/src/e72e9d6b13dd5e78168ffeae5d368924f6e307b5/django_socketio/example_project/chat/static/js/chat.js?at=default

But i don't find a way to make an app for corona sdk to interact with a channel. I managed to connect to the server with:

socket.connect( my_ip, my_port)

but cannot find a way to subscribe or post/receive messages, can someone give me a clue? Will be highly appreciate it. :)



[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Contributor

  • 198 posts
  • Corona SDK

You are trying to connect to a websocket (which is a socket protocol) using a raw socket.


Reading about the library:



We see it uses (link is broken, should point to : http://wamp.ws/ )

RPC and PubSub framework using WAMP (WebSocket Application
Messaging Protocol).

There is no implementation in Lua (http://wamp.ws/implementations/) so you will have to write one. This means you aren't going to be able to just call a method like in Javascript. Javascript's implementation is REALLY simple since it expects the browser to already have HTML5 Websocket functionality.


Look at PHP's implementation. This is more like what you need to do. I've already done a lot of work on this in the form of :




I may split the pure Websocket functionality out of it in the next month or 2, but for now you'll have to use it as a guideline in developing your own Lua Websocket functionality.

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Enthusiast

  • 86 posts
  • Corona SDK

I have the same challenge.  We have a web socket that works with a Javascript client on an iPod touch.  The interface is really slow so we are considering a move to Corona SDK.  It looks as if we need a WAMP implementation for Corona SDK.   I have written a lot of code but never at the network layer, so this would be a new adventure for me.  Alternatively I could write a Java extension on the other end for UDP or TCP.


Do you have any recommendations?  


Has anyone made any progress and WAMP?




[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 7 posts
  • Corona SDK

So Guys, how i did this:


I have my own server, where i'm using first apple and gogle push notification solution (simply i can send pushes).

Then i wrote few api's, like send message, store messages in mysql, load unreaded messages, etc... (the app have more functions what are working over api requests...)

The the process is: after starting the app, we receive pushID from apple (or google project), what we store or update in mysql with our name (and other details). We can read the users (list) from mysql,(if we want, we can see only the online users. Any update functions, what are goned over http i found so slowly, so by this reason i use node.js on the server, where we can 'log in' if we are online. The difference between other solutions - in this way the client updating his status like online or not. In this way we can send messages for groups, channels, rooms, etc...)

So, when we want to send a message for one user, then we choose him from the list for example. The next api what we call - message sending api. This reveive the 'from', 'to', and 'message' info. First, the api save this message to the database with the from and to details, and with timestamp. Then read the actual pushID of the user (from the database) and send a push message (the database include what type is the phone -ios or android, and use the right message sending process).

In the other side, if the app is not running, or in the background, then a simple push message coming. If the app is runing in the foreground, then we see just a popup, and if we are in the window where we are chatting with the actual user, then we just see a next row with the message.

If we are totally offline (i mean just not running the app), and have the push message, but we're open the app later, then: the fist is to load unreaded messages. This goes one-by-one (we limited the readable rows from db to 1, and ordered by timestamp). So we just read the message, save locally, and when all is done, we start again the proc.... When we receive nil ( zero answer) then the re-reading is stopped.


By this way for me to receive, send, load unreaded messages are fast, simply, and trusty.


If you need any help to build up some similar things, or use one of the services, just let me know, becuse i should need some testers for my other server-api communication services.


Good luck.

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Guests

So here is what I did to bridge Corona to socket.io(using noobhub),  I have a socket.io server that I really don't want to change how it works due to how other webclients connect etc.  But socket.io and corona do not get along as far as I could find.


So I just added noobhub to my socket.io application, dropped the node,js in /lib/noobhub and

basically just added this to my existing socket.io app:

var noob = require(__dirname + '/lib/noobhub/node')(app);
var net = require('net');noobsocket = new net.Socket();
noobsocket.connect(1337, '');
//send to noobhub
noobsocket.write(new Buffer('__JSON__START__{"fromsocketio":"test noobhub data"}__JSON__END__'));

and in noobhub I did have to modify it a liitle as well to connect back to the socket.io server

added this as well as some lines to trigger emit() back to socket.io

var ioclient = require(__dirname +  '/../../node_modules/socket.io/node_modules/socket.io-client');io = ioclient.connect('');
//send to socket.io
io.emit('fromnoobhub','test socket.io data');

This seems to work pretty well so far, not sure if it is a great solution but it certainly seems like it works well so far.