pubnub module

Monkey Forums/Monkey Programming/pubnub module

Skn3(Posted 2012) [#1]
Following from my previous thread where someone was talking about networking in monkey, I spent a little time today getting pubnub working in html5 and flash!

See the demo here:
http://www.skn3.com/junk/pubnub/MonkeyGameHtml.html

It was incredibly straight forward, and doesn't require anything special to be done to your project files. The required pubnub source and dom elements are attached at runtime.

You can download the example + module here:
http://www.skn3.com/junk/pubnub/pubnub.zip

I don't really have time to continue development on it and just wanted to have a try. Is anyone willing (got the time?) to continue where I left off and implement this for the other targets?

[update] I tweaked the demo to use hard coded font colors (seperate font for each color) and not apply any SetColor ... so it now shouldn't run like a dog :D

[update again]I have now added a flash target to the module! You can check the example and switch between html5 and flash versions...


slenkar(Posted 2012) [#2]
nice demo,
it says on the website 5 million messages per month are free ^_^
the messages are held on the pubnub servers?


Skn3(Posted 2012) [#3]
Thanks,
Yup 5 million free which is pretty damn good and no need to pay for a server as its stored on theirs :D


Fryman(Posted 2012) [#4]
I like it and will use it!


Skn3(Posted 2012) [#5]
Updated with a flash target...


Beaker(Posted 2012) [#6]
Thanks skn3. Just what I needed.


frank(Posted 2012) [#7]
Excellent work! That editor is so nice and fluent... Any chance you'll make that into a library? :)


MikeHart(Posted 2012) [#8]
5 million messages can be used up very quickly. Just do the math.

But thanks for the module. It is always good to have more possibilities.


Skn3(Posted 2012) [#9]
1 thousand people could play for 39 minutes a day at 70 messages a minute (1 a second plus 10 additional). Yeah not a huge amount, but fairly good for messing around with! I wonder what the limit of number of accounts is, you could potentially setup a webserver to list running games and then divert connecting users to appropriate pubnub account keys, each with their own 5 million message limit. I dunno if that breaks any terms/conditions they have though...

Thanks for comments btw, now any brave soul want to tackle one of the other targets?

A decent server would cost you about minimum £100 a month plus then the additional time of coding a steady infrastructure that can scale... lets say minimum 4 months (probably more like a 8-12) of development? starts to work out less expensive then you first think...

There is another service http://www.pusher.com that offers a more competitive rate! I wonder how hard it would be to write a "dirty" pubnub server in node.js or something! (and then swap out the destination in the library)

Excellent work! That editor is so nice and fluent... Any chance you'll make that into a library? :)


Do you mean the chat pane and input box? take a look at the sample code its fairly straightforward, nothing fancy.


MikeHart(Posted 2012) [#10]
huh?

1 thousand people could play for 39 minutes a day at 70 messages a minute (1 a second plus 10 additional)
.

I get then 81.900.000 messages in on Month.

1000 people x 39 minutes/day x 30 days x 70 messages/minute.


Skn3(Posted 2012) [#11]
Whoops I miss-calculated!

So roughly twenty people could play for 2 hours a day on 70 messages a minute.

(5,000,000 / (70 * 60) / 2 / 30)


Tibit(Posted 2012) [#12]
This is really cool! :)


Xaron(Posted 2012) [#13]
Indeed. They lowered this to 1 mio. messages free per month. What does "message" mean in this context?


Skn3(Posted 2012) [#14]
oh cool they have a pay as you go method now... much better!

A message is any message pushed to them or pushed from them to a user. So that means if you had 250 people subscribed to a channel and 1 message was sent that would count as 251 messages. 1 used to send to pubnub and 250 to send that back out to all of the subscribers.

So in this context.. if I send a message on the demo and 4 people are connected that is 5 messages.

The pricing model is not that great for indies but I guess their new scaled pricing is a bit better!


NoOdle(Posted 2012) [#15]
Nice! I did notice on HTML5 (Safari) I don't see any chat history, it loads the history in flash version.


Skn3(Posted 2012) [#16]
Yeah I noticed that intermittently. Maybe Xaron could nail that bug, I'm sure its probably just a typo or something...


Xaron(Posted 2012) [#17]
Ah well. Got it to work under Android. :)

Ok, but now I have the problem that I have strings in Javascript but JSON objects in Android. So if I send something from Android to HTML5 I get something like

object Object


as return value. JSON objects are just pairs, so the first one is the key and the second one is the value. But I have no clue at the moment how to make a string from an JSON object in Javascript (HTML5)?

In Java I just do (in a loop):
JSONObject o = response.getJSONObject( i );
String s = o.getString( _jsonKey );



Skn3(Posted 2012) [#18]
if you force communication to be string based (eg convert json to string before sending) then you could rely on the each of the targets own json implementation to then translate back to json object?

or have I misunderstood?

[edit] this could also help?
http://stackoverflow.com/questions/1116708/getting-first-json-property


Aman(Posted 2012) [#19]
Will this be combined with mnet or be a standalone module? There are multiple topics around the forum about this and it started to be hard to follow all of them.


Skn3(Posted 2012) [#20]
Xaron is combining this into mnet :D


Xaron(Posted 2012) [#21]
Yes!

So the next version of MNet will have http requests and pubnub.

And BTW: I got my problem solved! So messaging from Android to HTML5 and back works (in between of course too)!


Tibit(Posted 2012) [#22]
That is killer stuff :)


Skn3(Posted 2012) [#23]
Cool, what was the issue?

I still think it would be cool to write a pubnub server to bypass message limits! Maybe I'll write one in nodejs when I find a minute..... When!