pubnub module

22 replies to this topic
Posted 1+ years ago #1
Skn3

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...

 
Posted 1+ years ago #2
slenkar

nice demo,
it says on the website 5 million messages per month are free ^_^
the messages are held on the pubnub servers?

 
Posted 1+ years ago #3
Skn3

Thanks,
Yup 5 million free which is pretty damn good and no need to pay for a server as its stored on theirs :D

 
Posted 1+ years ago #4
Fryman

I like it and will use it!

 
Posted 1+ years ago #5
Skn3

Updated with a flash target...

 
Posted 1+ years ago #6
Beaker

Thanks skn3. Just what I needed.

 
Posted 1+ years ago #7
frank

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

 
Posted 1+ years ago #8
fantomEngine

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.

 
Posted 1+ years ago #9
Skn3

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.

 
Posted 1+ years ago #10
fantomEngine

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.

 
Posted 1+ years ago #11
Skn3

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)

 
Posted 1+ years ago #12
Tibit

This is really cool! :)

 
Posted 1+ years ago #13
Xaron

Indeed. They lowered this to 1 mio. messages free per month. What does "message" mean in this context?

 
Posted 1+ years ago #14
Skn3

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!

 
Posted 1+ years ago #15
NoOdle

Nice! I did notice on HTML5 (Safari) I don't see any chat history, it loads the history in flash version.

 
Posted 1+ years ago #16
Skn3

Yeah I noticed that intermittently. Maybe Xaron could nail that bug, I'm sure its probably just a typo or something...

 
Posted 1+ years ago #17
Xaron

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 );
 
Posted 1+ years ago #19
Aman

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.

 
Posted 1+ years ago #20
Skn3

Xaron is combining this into mnet :D

 
Posted 1+ years ago #21
Xaron

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

 
Posted 1+ years ago #22
Tibit

That is killer stuff :)

 
Posted 1+ years ago #23
Skn3

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!