Doing Facebook OAuth with Nokia S40/J2ME devices using App42 Platform

Share it now

Nokia Asha 3101 Doing Facebook OAuth with Nokia S40/J2ME devices using App42 Platform

Nokia S 40 Asha Series

Doing Facbook OAuth on Nokia S40 and J2ME devices is the biggest challenge while creating the social Apps for this platform because of unavailability of the Facebook J2ME SDK and inapp browser limitation of J2ME devices. App42 platform J2ME SDK provides an easiest and quickest way to do seamless Facebook OAuth on J2ME devices without going in to the complexity of underlying protocol.

Here are the few easy steps to do the FB OAuth for these devices.

Canvas URL : https://api.shephertz.com/cloud/1.0/social/facebook/saveFeaturePhoneFBToken?
Secure Canvas URL : https://apps.shephertz.com/socialkeys.php?
  • Also, make sure that sandbox mode is off for your app.
  • Register with App42 platform if not already registered and create an app for you.
  • Download the latest J2ME SDK from our public Git repo
  • Unzip the downloaded file and put App42_J2ME-x.x.x.jar in your project class path.
  • Now you are ready to do Facebook OAuth with just few lines of code as shown below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
ServiceAPI  sp = new ServiceAPI("YOUR_API_KEY","YOUR_SECRET_KEY");
String fbAppId = "YOUR_FB_APPID";
String fbAppSecret = "YOUR_FB_APP_SECRET";
 
String accessToken = null;
String [] appPermissions = new String [] {"publish_stream","friends_online_presence"};
String code = sp.buildSocialService().doFBOAuthAndGetToken(midlet, fbAppId, appPermissions);
//The Above call will open user login OAuth page in browser and will wait till user authorizes the app.
 
accessToken = sp.buildSocialService().getAccessTokenFromCode(code, fbAppId, fbAppSecret);
System.out.println( "  Token : " + accessToken);
Social socialObj = sp.buildSocialService().getFacebookFriendsFromAccessToken(accessToken);
Vector friendList = socialObj.getFriendList();
//This will return Facebook friends of user whose access token was passed.
  • In above snippet doFBOAuthAndGetToken method will do all the trick, it will open FB user OAuth page and will wait till user authorizes the app.
  • Once user does the authorization, user’s acccesscode is redirected to our server and being further received by your app and being returned by this method.
  • Once you have got the acceess code you can make another call getAccessTokenFromCode to get the access token of that user.
  • The whole story ends once you get the access token with you. Now you can call getFacebookFriendsFromAccessToken on our SDK or can directly use facebook graph API for fetching other information of user.

You can use other App42 backend services like Gaming, Storage, File Storage, Messaging, Geo Spatial, Custom Code to make user engaging social app with writing any backend for J2ME/S40 devices. Start making beautiful Apps with App42 Cloud API S40 SDK. Here is the Sample Code to get you started.




fa3935b8 11e5 41c8 b56e 2f523cb5f9f9 Doing Facebook OAuth with Nokia S40/J2ME devices using App42 Platform






8931e3f4 f630 47a3 9675 fa5b55cf7e24 Doing Facebook OAuth with Nokia S40/J2ME devices using App42 Platform




Share it now
Be a fan!

Make Real-time multiplayer games using Unity3D

Share it now

unity logo Make Real time multiplayer games using Unity3Dappwarp Make Real time multiplayer games using Unity3DUnity3D is a popular cross-platform game engine for building sophisticated 3D games. Using AppWarp, developers can now add realtime communication in their Unity3D games to build beautiful, rich and engaging multiplayer games. The great thing is that developers can do this without any server side code or socket level programming as all the communication is managed by AppWarp SDK and cloud.

To help you get started, we have created a sample project that illustrates how to get the pieces together and set up the basic code required. Complete source code for the sample is available in our Git Repo. Below are some of the relevant code snippets. To initialize the SDK. You need to pass in your Api key and Secret key.

WarpClient.initialize(apiKey,secretKey);

Now create and add a Listener which implements the relevant WarpClient callback interfaces and connect with the server.

Listener warpLayer = new Listener();
WarpClient.GetInstance().AddConnectionRequestListener(warpLayer);
WarpClient.GetInstance().AddNotificationListener(warpLayer);
WarpClient.GetInstance().AddRoomRequestListener(warpLayer);

Now simply call connect to establish your connection with the server.

WarpClient.GetInstance().Connect();

Once your connection is established and authenticated, you will simply join a room and subscribe it to receive its notifications.

WarpClient.GetInstance().SubscribeRoom(roomid);
WarpClient.GetInstance().JoinRoom(roomid);

After you have joined the room, you can start sending your user’s coordinates to other users in the room. In this example we will use our Chat api to do that

string json = "{\"x\":\""+transform.position.x+"\",\"y\":\""+transform.position.y+"\",\"z\":\""+transform.position.z+"\"}";
WarpClient.GetInstance().SendChat(msg);

Once the remote player also joins, you will start receiving messages from it. Handle them and move the cylinder representing it

		
public void onChatReceived (ChatEvent eventObj)
{
    Log(eventObj.getSender() + " sent " + eventObj.getMessage());
    SimpleJSON.JSONNode msg =  SimpleJSON.JSON.Parse(eventObj.getMessage());
    if(eventObj.getSender() != id)
    {
        appwarp.movePlayer(msg["x"].AsFloat,msg["y"].AsFloat,msg["z"].AsFloat);
    }
}

And thats it! Simply build and run your Unity3D application on two different endpoints and you will be able to see each other’s endpoint movements in realtime (a simple white cylinder).

opponent Make Real time multiplayer games using Unity3D

You can also add leader boards, reward management and push notifications to your game by importing the App42 Unity asset in to your project. For a complete list of backend APIs available, visit the App42 page.

Instructions on downloading this sample and getting your API Key, Secret Key and RoomId can be found in our GIT repo here. To learn more about AppWarp, check out the product overview.



3893cb46 e00d 48a3 ab37 ed895529743d Make Real time multiplayer games using Unity3D








5e4701b1 0391 4883 93c4 677289558295 Make Real time multiplayer games using Unity3D




Share it now
Be a fan!

How to add a leaderboard to your Cocos2D game

Share it now

First How to add a leaderboard to your Cocos2D game

App42 provides a rich set of leaderboard APIs. In this post, I will describe how to integrate your Cocos2D game with the App42 cloud framework and use its leader board APIs. Please see my previous blog post on why a rich leader board is important for your game.

Second How to add a leaderboard to your Cocos2D gameWe will use our Ninja Fight iPad demo game to walk you through the integration. Ninja Fight is a simple multiplayer game in which opponents have to strike each other with missiles while avoiding getting hit themselves. The game starts of by asking the player to enter its name. This is the name that will be used later to submit the score for the user.

GamePlay How to add a leaderboard to your Cocos2D game

Once two users have started fighting, the game will transition to the fight scene. This is where the realtime action will happen using AppWarp apis. Using AppWarp with Cocos2D was described in an earlier blog post. Players simply need to tap in the direction of the opponent to fire missiles. You can also move the player by dragging it using your finger on the iPad.

Leaderboard How to add a leaderboard to your Cocos2D game

Ninja Fight leaderboard

Once the game is over the user’s score is submitted and an option to view the game’s leader board is given. Upon selecting this option, the game’s leader board is displayed using our API. This will simply list the users who have submitted the top scores, their rank and the score.

Now to the actual code itself for saving scores and getting the top scorers! Here is the initial set up that you need to do once before you can use all the leader board APIs.

ServiceAPI *serviceAPIObject = [[ServiceAPI alloc]init];
serviceAPIObject.apiKey = APP42_APP_KEY;
serviceAPIObject.secretKey = APP42_SECRET_KEY;
ScoreBoardService *scoreboardService = [serviceAPIObject buildScoreBoardService];

To submit the user’s score to the cloud, its one simple API call

[scoreboardService saveUserScore:@"Ninja Fight" gameUserName:userName gameScore:score];

Retrieving your game’s top 20 scorers from the cloud is also straight forward.

Game *game=[scoreboardService getTopNRankers:@"Ninja Fight" max:20];
NSMutableArray *scoreList = game.scoreList;

The API works synchronously so you should perform the API calls on a back ground thread so as to not block your main thread. This is extremely easy using the performSelectorInBackground utility iOS method.

Complete source code for the game can be downloaded from our Git Repo with the Readme file containing the instructions on how to set up and get it working.

App42 provides a complete set of leader board APIs which allow you to add advanced social leader boards based on groups, weekly, daily top scorers etc. Similarly you can use our reward management APIs to manage in-app rewards and purchases. For a complete reference, visit this page.

Please send your feedback and queries to us at support@shephertz.com


Share it now
Be a fan!

Adding Back-end to HTML5 apps with App42 Platform

Share it now

HTML5 Adding Back end to HTML5 apps with App42 Platform

HTML5

App42 platform announces its Java Script API for Backend as a Service platform. Now, one can add backend to HTML5 Apps with few lines of code without writing any server side logic using  App42 platform. One can also choose to use different technical and business services based on app requirement and develop HTML5 Apps with  lesser time.

Here are the steps to add this in to your HTML5 Apps

  • - Download the latest App42 Java Script SDK
  • - Unzip the file and copy App42-all-x.x.x.min.js to your project  source.
  • - Add the following script tag in the your html page
  • script type="text/javascript" src="App42-all-x.x.x.min.js"
  • - Initialize the library using
  • App42.initialize("API KEY","SECRET KEY");
  • - Instantiate the service that one wants to use in the App, e.g. using User service one has to do the following
  • var user = new App42User();
  • - Now one can call associated method of that service e.g. user creation can be done with the following snippet
  • user.createUser(userName, pwd, email,{
    success: function(object) {
    // Callback for Success },
    error: function(error) {
    // Callback for error }
    });
  • - Executing above method will create user for your app in App42 cloud.
  • - You can login to AppHQ console and can see the created user there.
  • - You can also use your UserSample.HTML/StorageSample.HTML shipped with distribution for more details.
  • - Similarly one can use other App42 services like File UploadGamingNoSQL Storage to make user engaging social Apps for HTML5.

Share it now
Be a fan!

Adding Backend to BlackBerry 10 webworks with App42 Platform

Share it now

BlackBerry 10 Adding Backend to BlackBerry 10 webworks with App42 Platform

BlackBerry 10

App42platform is now equipped with BlackBerry 10 webworks SDK. This means one can make cloud enabled apps with scalable App42 platform with few lines of java script code. One can choose from different business and technical services available in App42 platform to make a user engaging and feature rich app for BlackBerry 10.

Here are the steps to add it in  BlackBerry 10 webworks App

  • - Add the following script tag in the html page
  • script type="text/javascript" src="https://raw.github.com/shephertz/App42_JAVASCRIPT_SDK/master/App42-all-0.6.0.min.js"
  • - Initialize the library using the following java script code
  •  App42.initialize("API KEY","SECRET KEY");
  •  - Instantiate the service that one wants to use in the App, e.g. using User service one has to do the following
  •   var user  = new App42User();
  • - Now one can call associated method of that service e.g. user creation can be done with the following snippet
  •  user.createUser(userName, pwd, email,{
                            success: function(object) {
                // Callback for Success                 },
                            error: function(error) {
                // Callback for error               }
                        });
  • - The above snippet will create a user in App42 cloud, if operation is success one will get the callback in success method however if it fails, error method will get invoked as callback.

Download the SDK and sample code from our BlackBerry 10 webwork repository to get started.


Share it now
Be a fan!

Engage users through social leader boards

Share it now

Mobile games have become an integral part of the industry landscape over the last few years. With devices becoming more and more powerful and internet connectivity becoming ubiquitous, there is potential for a lot of innovation and these are exciting times for mobile developers. However, with increasing competition, the challenge is to make games that keep their users constantly engaged and compel them to keep coming back.

Screen Shot 2013 03 18 at 10.55.31 AM Engage users through social leader boards

Daily and All-time leader board

Adding leader boards to your game is a natural way of engaging users. Hard core gamers like to brag and are always interested in beating the best and it is not uncommon to see them posting screenshots with their highest scores on their Facebook walls. However, most of the users of a game are not going to be hard-core gamers and would not be interested in seeing the leader boards and posting scores on their Facebook wall if their ranking is say 21,053! It will also not interest them in seeing who is at the top of the tree and with how many points, if they are not even close. How can we engage such casual gamers through leader boards? The idea is to develop leader boards, which are more relevant to the user by making them social. We make them social by showing a user where they stand amongst their friends. So while it may not interest a casual gamer to see how they are doing compared to random strangers across the world – they would want to see how they are doing compared to their colleagues, classmates, siblingsetc.

Screen Shot 2013 03 18 at 10.58.45 AM Engage users through social leader boards

Friends and Global leader board

A prerequisite for mobile developers to build such relevant and engaging experiences, is the data storage on the cloud and its efficient retrieval in the desired form. Its time consuming to deploy your own DB on the cloud, cluster it, secure it and then expose it as a web-service in the form desired by your game running inside a user’s device. App42 leader board APIs make this task easy by providing SDKs to access and save your game scores on our readymade backend. App developers can determine the relevant user list according to their App’s user management such as Facebook friends, Twitter followers, Instagram followers or their own in-App buddy lists. Through simple API calls from the SDK, App42 backend will fetch the data requested from the backend. Of course, App42 leader board APIs also provide global leader boards and leader boards based on time such as daily, weekly top scorers etc. Another great thing is that you are not tied to a particular platform since App42 leader board SDKs are available for all devices like iOS, Android, J2ME, Windows Phone, Blackberry etc.This is great if you are a mobile developer as you need not hire a backend expert or learn these technologies yourself, reducing your time to market. Go ahead and try right now!

8046709a 9a4d 4fc3 910a a3e6abc0436f Engage users through social leader boards

Share it now
Be a fan!

Why Backend as a Service – BaaS cannot be ignored for developing Apps

Share it now

BaaS2 Why Backend as a Service   BaaS cannot be ignored for developing AppsIn todays day and age one does not have the luxury to build applications, which have release cycles beyond few months leave apart years like before. One needs to be super agile and focus on your core expertise, leverage whatever one can use and release the app at the earliest. Sticking to the non-invented-here syndrome, just might be a recipe for disaster.

You imagine about an App idea, be it Mobile, Web, Gaming or Social App and most likely you will find it in one of the AppStore, if not most likely someone, somewhere in some garage or a big company is working on the same idea. Time to market is essential, releasing the app late might just loose its relevance in the market or catching up with competition might become a daunting task.

Developing a non-trivial App requires expertise at various layers of the architecture and platforms.

Device : iOS, Android, Windows 7/8, HTML5, J2ME for Mobile devices

Server Side : PHP, Ruby, Python, Java, Scala, Groovy, Closure, .Net, Node.js etc

Databases : RDBMS, NoSQL, Embedded etc.

Cloud Computing : IaaS – Infrastructure as a Service, Traditional Hosting, PaaS etc.

The developer also needs to have knowledge on setting up the right configuration for Firewall ports, Security, patches, high availability, Scalability, Performance etc.

System Monitoring & Management – The health of the backend servers and managing the servers and data (e.g. Backups), geographical redundancy etc.

For a  developers the list activities to be done and skills required across platforms and layers of architecture might consume too much of their time since instead of focusing on their core features. Lot of time goes into non-core activities.

Developers eventually might think that their idea to see the light of the day might be quite far from what they had imagined.

Even if the developer is an expert, the sheer time and effort it will take to achieve this might be more than the time and budget they have.

- It might not be cost effective for them because taking up virtual machines with IaaS provider is quite expensive than one imagines and paying them even before your App is released in the market itself is something which might effect his total budget significantly.
- Development of server side logic requires different skills, different than Device technologies and might consume lot of time and effort.Even if one decides to develop in-house, which in turn might inflate the cost.
- For Service companies engaged in outsourced App development. The development is done by two separate teams, one doing development on the device/client and the other specializing on the server side. The device team is always dependent on the server team and they always end up fighting on the desired interface or their frequent changing. This dependency adds on to unnecessary pressures on time lines and team morale.
- Managing your servers and infrastructure for Non-Functional requirements is complex e.g. Scalability, Performance  High Availability, Security etc. Also requires lot of time, effort and cost. Not to forget specialized skills especially for capacity planing, sizing and setting up the Physical Architecture.

What if some of the pain points illustrated above is taken care by an external service provider. Somebody whose bread and butter is to manage backend apps. 

- Continuously keeps on adding new features and maintaing current ones with public interfaces which are versioned.
- Keeps the developer oblivious of the complexities of the deployment of the app on the cloud, server installation and its management.
- Offers out of the box features for most of the common cases.
- For the ones which requiers some custom logic gives an execution environment for custom code to be deployed and run on the backend server along with the existing servers.
- Provides native SDKs for all popular platform for device and web.
- Makes supporting more than one platform easier since the backend remains the same only the native SDKs, which have similar interface has to be changed.
- Provides a Management Console which allows access and management of all the data generated through the usage of the SDKs

Backend as a Service - BaaS comes to the rescue. It is a logical evolution of Platform as a Service – PaaS, which tries to solve the above pain points and more. BaaS is a layer which sits over PaaS. Most often it provides a REST based interface to all its services which can be accessed through native SDKs. A further more specific platform for Mobile development is Mobile Backend as a Service – MBaaS

- The developer just needs to add the respective native SDK library based on the technology in which he is developing, write few lines of code to integrate and voila
- Gets out of the box functionality from day one. No need to manage servers, spend time in writing boiler plate code
- Have flexibility to write custom code.
- No need to learn, hire or develop most of the server side functionality
- And with all of the above save time, effort and cost.

Backend as a Service is getting evolved everyday. Its also participating in the MEAP vision  helping app developers to become successful which MEAP – Mobile Enterprise Application Platform a term coined by Gartner in their Gartner Magic Quadrant.

Applying the cliched 80-20 rule. Intention is to cover 80% of the features which one requiers on the server side for App development. For remaining 20% features, some BaaS Providers have started offering provision to run custom code on the cloud. One can even mash two or more APIs and carve out a higher level facade API.

Most Common services which the BaaS Providers offer are :

- User Management
- Storage
- Push Notification
- Social
- Geo Spatial

Some of them provide many more services across domains

Already Backend as a Service is being used by many developers across platforms. The pace at which it is evolving, it is surely a technology which one cannot ignore and to reckon with.


Share it now
Be a fan!

Build cross-platform realtime games and apps using Mono

Share it now

monotouch Build cross platform realtime games and apps using Monomonodroid Build cross platform realtime games and apps using MonoXamarin has developed a powerful platform on top of Mono which allows developers to build Native iOS and Android apps using C#. This is great for .Net/C# developers who want to build iOS/Android apps but are not experienced in Objective-C or JAVA. Another advantage of using Mono is that you can share almost all of your client-side business logic if you are building an app for both Android and iOS.

appwarp Build cross platform realtime games and apps using MonoYou can now build cross-platform iOS and Android games and apps on top of the Mono platform using AppWarp cloud gaming network. Unlike many 3rd party iOS/Android libraries which require developers to write a proxy/projection layer on-top of them when including in a MonoProject – AppWarp Mono library works as is. This is because we have specially built a Mono compatible flavor of our SDK eliminating this pain point for developers.

We have developed a simple demo chat application illustrating how you can integrate AppWarp’s mono compatible library in to your project and get access to the powerful AppWarp real-time multiplayer cloud network. Both the Android and iOS versions of the applications follow the same pattern. There are two screens in the application – a Join Screen and a Chat Screen. The Join Screen takes the user name as input and joins a room in the AppWarp cloud. The Chat screen allows the user to send and view chat messages in real-time.

Android Join 246x300 Build cross platform realtime games and apps using Mono

Android Demo Chat Join Screen

iPhone Join 152x300 Build cross platform realtime games and apps using Mono

iPhone Demo Chat Join Screen

Join Controller/Activity code snippets.

 WarpClient.initialize(Constants.API_KEY, Constants.SECRET_KEY);

WarpClient.GetInstance().JoinZone(this.nameTextField.Text);

WarpClient.GetInstance().JoinRoom(Constants.CHAT_ROOM_ID);

iPhone Chat 153x300 Build cross platform realtime games and apps using Mono

iPhone Chat Screen

Android Chat 221x300 Build cross platform realtime games and apps using Mono

Android Chat Screen

Chat Controller/Activity code snippets

WarpClient.GetInstance().SendChat(this.inputTextField.Text);

public void onChatReceived (ChatEvent eventObj)

{

    String sender = eventObj.getSender();

    String message = eventObj.getMessage();

}

Complete source code for both Android and iPhone chat applications can be found on our GIT repo here. You can see how we have shared almost all of the C# code in the iOS controller and Android Activity class is the same.

Interested in learning more about AppWarp?

Take a tour or Sign up right away!.

Also take a look at our cross-platform Leader board and push notifications apis for adding comprehensive out of the box cloud support in your games and apps.

Do try these out and share your feedback with us on support@shephertz.com


Share it now
Be a fan!

How to Create Geo Spatial Enabled Apps

Share it now

Today a significant market share is acquired by Geo Spatial enabled apps on all famous app stores. There are few consideration and challenges while making Geo enabled apps. Lets first look into what it really takes to give the power of Geo Spatial to your app. There are two main components in Geo Spatial enabled applications, one is creating the data source for geo points and another in searching the data source for given input. For example, if you want to create an app for café search, you have to first create the data source of café by creating data points in it. Here data points are individual café at specified location. Second point is searching those data points in the data source from given geo input. For example searching the nearby café from current location of user. Creating data source and searching in it require GIS data base like postgrase, mongoDB etc to be installed and should be accessible from your app. You might need to create HTTP interface over it and an admin interface for populating/creating the data points. You also have to plan its scalability, high availability, data backup and other infrastructural considerations. If you dont want to do all above stated things, App42 Geo Spatial APIswill help you in only focusing the business logic of your app and rest will be taken care by our platform. Creating Data Points for your app, can be done with App42 APIs or through AppHQ UI interface. Similarly there are already cross platform APIs available to do the search on your data source.


Share it now
Be a fan!

Challenges in Cross Platform Push Notification

Share it now

Today all famous apps run on almost all platform to cater most of the audience. To develop and support all platforms to your app requires lots of platform specific things to address. There are some frameworks like PhoneGap which has reduced this work and provided a way through which one can write entire app using this framework and then convert this into target platform like iOS, Android and more.

However there are still lots of things which are beyond the offerings of these frameworks. Making cross platform Push Notification support is one of them. Before we go into detail of challenges, lets see what are the key component in Push Notification Engine.

Key components in Push Notification Engine is described below

  1. Push Server which will send the notification to target client once message is available. Each provider has its own Server like APNS for iOS, GCM server for Android, MPNS for Windows and so on. It also provides the interface to register the application for push enablement.
  2. App Back-end Server which will send the notification to Push Server (APNS/MPNS/GCM etc)
  3. Push Client which runs on device and keeps on listening to server for incoming messages. This client is background process and is common for all applications running on the device. Once message is received it will wake up the app for which message has been received.

Challenges on Supporting Cross Platform Push Client

  • In order to make cross platform push, your custom push client should work on all devices. However there are some limitation in running a background process on iOS and Windows devices.
  • Taking app to wake-up state is another challenge imposed on some devices.
  • Spawning one push client for each app is not a wise decision because you will end up using lots of battery power.
Since these limitations are imposed by device OS itself, you don’t have a way to solve it on device. However a hybrid model can be thought of where Push Server and App Back-end Server can be cross-platform supported however device side will still use its native mechanism for receiving the Push notifications.

App42 Push Notification Service uses the same technique to deliver cross platform push notification to your app with out writing any backend server. You can send a message to any target platform from any device/platform using following sample Android code snippet

1
2
3
4
5
String userName = "Nick";
String message = "Hi Nick! you have won 10 points";
ServiceAPI api = new ServiceAPI("<API_KEY>","<SECRET_KEY>");
PushnotificationService pushnotificationService = api.BuildPushnotificationService();
PushNotification pushNotification = pushnotificationService.sendPushMessageToUser(userName,message);
App42 platform will fetch the underlying device platform of registered user internally and will use the respective mechanism for sending message to user.
App42 Server handles the complexity of sending message mechanism to Push Server Provider like APNS/MPNS/GCM etc. As an app developer you will only focus on your business logic, rest will be taken care by App42 platform.
8046709a 9a4d 4fc3 910a a3e6abc0436f Challenges in Cross Platform Push Notification                      8931e3f4 f630 47a3 9675 fa5b55cf7e24 Challenges in Cross Platform Push Notification

Share it now
Be a fan!

Picking the right communication protocol for your game

Share it now

In this blog post, I will discuss the trade-offs of the commonly used protocols for communication in realtime games. One of the most essential components of building a multiplayer game is the communication between players. Picking the right protocol for your game is crucial and impacts your game’s architecture and performance.

AJAX/Long polling

In this technique the client always keeps a parallel pending HTTP request open with the server. The server only responds to this request when it has something to send (push) to the client. As soon as the response arrives, the client will again open a new pending HTTP request and send to the server. The good thing is that the same REST communication layer will work across all devices and browsers allowing you to reuse a lot of the logic if building a cross platform game. Another key advantage is that the HTTP protocol takes care of all the network topology/proxy/firewall issues for you and your games should work in almost any possible setup. The other advantage is that there is a wide array of options available to implement your game server – which is simply a web server in this case.

The main drawback with this approach is when it comes to performance. Every request by the client sets up a new underlying TCP connection thereby increasing the round trip times. Another thing to keep in mind is the large message sizes owing to the protocol’s own headers increasing both bandwidth and processing at both client and server. Yet another limitation is that any binary data you want to send will require to be Base64 encoded/decoded as HTTP is string based. Finally you don’t have control over browser time outs and need to tune the timeout values carefully. This technique is only recommended if you are building a soft realtime game which has a low frequency of messages exchanged between the users such as turn based card games.

AJAX Server Push

Another AJAX based technique is the server push. This technique allows the the server to send a stream of notifications back to the client without client sending a new HTTP request. The idea is to send an initial request form the client and then the server keeps responding with multipart portions whenever it has data to send back to the client without completing the response. This solves the problem in long polling of having to establish a new connection after every response but the channel is one way i.e. from server to client. When the client has new information to send to the server, it will still need to send a new HTTP request. This makes it ideal for applications such as facebook and twitter feeds where the server keeps updating the client. A deeper discussion on this can be found here. An upcoming feature of HTML5 known as server side events is aimed to provide the same behavior without the need of doing all the multipart response work on the work from the server.

TCP

This is the most commonly used protocol in realtime games. The bidirectional connection is kept alive throughout the life of game play – making it easy to push async updates from the server to the client. It frees you the strict request/response HTTP paradigm which hinders the long polling approach. The other advantage is the ability to send binary data and flexibility to develop your own messaging protocol optimized for your game’s scenario. This is great plus as it reduces the message size, bandwidth and doesn’t require Base64 encoding. Since the persistent bidirectional TCP connection is initiated from the client – it also works across most NAT topologies and doesn’t require you to do something like UDP punching to communicate when behind a NAT. A good understanding of socket programming is a must before you begin as investigating bugs and issues can become quite time taking. The other thing to consider is that while most devices allow TCP socket programming – there are differences in the way they are exposed to the developer so you might find your iOS layer looking quite different to your WP 8 layer for example. Which also means that you may have different bugs in different platforms of your game!

UDP

One can think of UDP as a simplified version of TCP. Its simple in that it does less (no sequencing, no sliding window) and guarantees less (no reliability, no in order delivery). Since the reliability and sequencing overhead is not involved, it makes UDP even faster than TCP on an average. Similar to TCP, UDP allows you to send binary data and means you can build your own optimized messaging protocol. The obvious drawback are of course lack of reliability and potentially out of order delivery of messages. The other problem is when it comes to NAT traversal as there is no persistent connection kept alive as in the case of TCP. You will have to employ techniques such as UDP punching, STUN etc. to get your game to work when behind a NAT. Also many cellular network providers will simply block UDP traffic making your game unplayable when on 3G.

If you do decide to use UDP – its recommended that you use TCP in conjunction with UDP. Use TCP for operations such as join/leave room, chat, sending and responding to invitations etc. Essentially use it for operations that are not hard realtime but can impact other players and the game play directly. You can then use UDP for exchanging in game operations such as updating car coordinates etc. in a car racing game for example.

WebSocket

The most popular feature of HTML5 for game developers is WebSocket. This is essentially a wrapper around a TCP connection between the end users browser window (tab) and the server. WebSockets allow you to send binary data from the browser thus opening up the possibility of building your own custom optimized protocol optimized as in the case of TCP and UDP. Most of the advantages and disadvantages of TCP directly apply for WebSockets as well. Note that while sending and receiving data from a web socket is straight forward – you need to do some additional work on the server. This is because web sockets do their own binary encoding on top of TCP. So you need to special case this when handling TCP connections on your server if you are supporting both native TCP connections and WebSocket TCP connections. Another thing to be vary of when selecting websockets is that they are not yet supported on all browsers. A demo of a multiplayer game using websockets can be found here.

That covers the most common technologies and protocols that game developers use for communication in multiplayer games. Hopefully you will find this post useful and good luck in building your multiplayer game!

What we are doing?
appwarp logo Picking the right communication protocol for your game

We have developed AppWarp in a way that we abstract all the nitty gritty details of protocols and their implementation from game developers. AppWarp supports TCP/UDP in the native SDKs and WebSockets in the Javascript SDK. This allows you to build cross-platform games easily and in a short time as you don’t need to spend time debugging and testing your client and server communication layer code.



3893cb46 e00d 48a3 ab37 ed895529743d Picking the right communication protocol for your game







58373e51 32a5 4e21 ac5a 38d4c3db8a3a Picking the right communication protocol for your game




Share it now
Be a fan!

Make realtime multiplayer games using cocos2D

Share it now

HelloWorld Make realtime multiplayer games using cocos2D Cocos2D is a popular open source framework for building iPhone games. Its quite powerful and can be used to develop a wide range of 2D games. Here is a list of some of the apps on the appstore developed using Cocos2D.

This blog describes how to develop realtime multiplayer games using Cocos2D by integrating with the AppWarp apis. AppWarp is a new cloud framework which allows you to develop cross-platform realtime multiplayer games by taking care of all the networking, routing and messaging between players. You can get an overview of AppWarp here.

There are many tutorials on how to use Cocos2D – one great one can be found here.

The best way to get started on making your first realtime multiplayer Cocos2D game is to download the sample project code from our git repo here. Its a simple soccer ball kicking application which illustrates the realtime multiplayer aspect integrated in to Cocos2D. Follow the 5 simple steps in the README file to quickly get up and running.

Here is a screenshot of how it should look once setup.

photo 300x199 Make realtime multiplayer games using cocos2D

Enter your name in the first screen and hit ‘start’. Now run the app on another simulator or device and enter a different name and hit ‘start’.

Both the devices should see the following screen at this time. Start tapping on the screen and see the balls flying from both the devices/simulators!

photo 1 300x200 Make realtime multiplayer games using cocos2D

The high-level operation performed in this example are

1. Initialize the AppWarp SDK with your keys

2. Connect and JoinZone with the name entered.

3. Subscribe and Join the room you created.

4. Use the SendUpdatePeers api and OnUpdatePeersReceived event to do the magic.




3893cb46 e00d 48a3 ab37 ed895529743d Make realtime multiplayer games using cocos2D







58373e51 32a5 4e21 ac5a 38d4c3db8a3a Make realtime multiplayer games using cocos2D



Interested in learning more about AppWarp?

Visit our iOS developer guide.

Download the AppWarp iOS SDK.

Overview of AppWarp

Integrate cloud Leader board apis in your game

Send cross-platform push notifications

appwarp logo Make realtime multiplayer games using cocos2D

Please try this out and share your feedback with us on support@shephertz.com


Share it now
Be a fan!

How to Configure MongoDB HA Replica Set on AWS EC2

Share it now

mongothumbnail How to Configure MongoDB HA Replica Set on AWS EC2It has been always tedious task for choosing right configuration for MongoDB on AWS EC2. Choosing right configuration in this environment is always a challenging and it takes lots of time to make your system Production Ready.

You can use following configuration and steps to install MongoDB in EC2 environment for creating Production Ready HA replica set.

All it needs is two machines that will be used as PRIMARY(Master) and SECONDARY (Slave) node and one ARBITER machine for the replica set. However it might get changed based on your application requirement and you can opt for higher number of nodes based on your need. ARBITER is only required in case of even number replica set. If you want to maintain replica set with one PRIMARY and two SECONDARY, ARBITER is not required.

Hardware Requirement

  1. Two 64 bit EC2 instances of medium/large or higher configuration based on your app requirement for PRIMARY and SECONDARY node. There is a data storage limitation of using 32 bit machine and can only support up-to 2.5 GB of storage.
  2. A small 32 bit EC2 machine for MongoDB ARBITER.
  3. It is recommended to have machines in different availability zone to make it High available in-case shutdown of one availability zone.
  4. Use Ext4 EBS volume to support I/O suspend and write-cache flushing for multi-disk consistent snapshots.

Installation steps

  1. Create and Launch an EC2 instance of required configuration as stated above for PRIMARY, SECONDARY and ARBITER nodes.
  2. Create an EBS volume of required size to be used for MongoDB storage for both nodes.
  3. Connect to EC2 instances on PRIMARY and SECONDARY node via SSH
  4. Make a Ext4 file system on both node via sudo mkfs -t ext4 /dev/<Created_EBS_Volume>
  5. Create directory /data/db or any other of your own choice and mount it to attached volume using sudo mount -a /dev/<Created_EBS_Volume> /data/db
  6. Edit your /etc/fstab to enumerate it on start up of instance using sudo echo ‘/dev/sdf /data/db auto noatime,noexec,nodiratime 0 0’ >> /etc/fstab
  7. Download and Install MongoDB on all instances.
  8. Start the PRIMARY node with following command in MongoDB directory using mongod --rest --replSet myHASet (Where myHASet is the name of Replica set, you can choose any name of your choice)
  9. Go to Mongo treminal in MongoDB directory.
  10. Initialize the set using command rs.initiate() on mongo terminal
  11. Check the status of Replicat set after initialization using rs.status() command.
  12. If initialization is success you will see OK in the output something like this{
    "set" : "sample",
    "myState" : 1,
    "members" : [
    {
    "name" : "<PRIMARY_HOSTNAME>:27017",
    "self" : true
    }
    ],
    "ok" : 1
    }
  13. You can also check the status on http://<PRIMARY_NODE>:27017/_replSet
  14. Your Primary node is ready to use now. You can insert/update document on this node.
  15. Now start SECONDARY node with same command as on primary mongod --rest --replSet myHASet
  16. Now tell the PRIMARY node to add SECONDARY node in replica set. Go to mongo console on PRIMARY node and add this using rs.add(“<SECONDARY_HOSTNAME>”);
  17. If addition is successful you will see the response { "ok" : 1 }
  18. Once your SECONDARY node is attached to replica set you can check the status on http://<PRIMARY_NODE>:27017/_replSet
  19. Now start the ARBITER node using mongod --rest --replSet myset --oplogSize 8
  20. Add the ARBITER node in replica set using command rs.add( { _id:2, host:”<ARBITER_HOSTNAME>”, arbiterOnly:true } )
  21. Once ARBITER is added successfully, you are done with the configuration and your replica set is ready to use.
  22. Got o http://<PRIMARY_NODE>:27017/_replSet and you should be able to see the status of each node as seen in below scree shot.
  23. ReplicaSet1 300x113 How to Configure MongoDB HA Replica Set on AWS EC2
  24. To test the replica, take down the primary node, and see if SECONDARY is able to pick up and will become PRIMARY node.
  25. You can fire the command db.isMaster() to check the status if SECONDARY node has turned up as Master node.
  26. You can additionally use horizontal sharding using shard cluster for scaling large volume of app data. Configuring shard cluster is not in the scope of this article.

Connecting Replica Set from JAVA API

  • After you have setup the replica set successfully, you can connect with using JAVA driver from your client application.
  • You can use following code snippet for making connection to replica set
1
2
3
4
5
List addrs = new ArrayList();
addrs.add( new ServerAddress( "&lt;PRIMARY_HOST&gt;", "&lt;MONGO_PORT&gt;" ) );
addrs.add( new ServerAddress("&lt; SECONDARY_HOST&gt;" , "&lt;MONGO_PORT&gt;"));
Mongo m = new Mongo(addrs);
DB db = m.getDB("&lt;NAME_OF_DB&gt;");
  • MongoDB driver is smart enough to connect to PRIMARY node only, in-case if PRIMARY node is down, it will automatically switch to another node for communication.

Here is an honest attempt to guide you to setup MongoDB on AWS EC2. Though this is an open forum and you all are open to post your comments if I have missed anything.

Also, if you don’t want to get into setting up the infrastructure and administration for MongoDB, you can directly use our App42 NoSQL Cloud Storage Service. This service can be accessed using our REST API or using native platform SDKs available in different languages like iOS, Android,J2ME, JAVA, PHP, Ruby, Windows Phone and C#.

      8046709a 9a4d 4fc3 910a a3e6abc0436f How to Configure MongoDB HA Replica Set on AWS EC2                  8931e3f4 f630 47a3 9675 fa5b55cf7e24 How to Configure MongoDB HA Replica Set on AWS EC2


Share it now
Be a fan!

Develop realtime multiplayer games on WP8!

Share it now

AppWarp Windows Phone SDK now supports WP8!

Today we’ve added WP8 to our list of supported mobile platforms allowing you to make realtime multiplayer games on WP8.

windows phone 8 logo new1 300x300 Develop realtime multiplayer games on WP8!

Windows Phone 8 was recently launched by Microsoft and already boasts of over 120,000 apps on its store. Read more about WP8 and all its feature here.

We have built our Windows Phone family SDK in such a way that the same SDK dll works for both Windows Phone 7.1 and 8. This means that if you are a WP developer, integrating your app with our SDK will be hassle free when switching between the two platforms.

To get you started, we have created a demo tic-tac-toe game using our WP SDK that works on both the platforms. This game illustrates how you use the SDK to build realtime-multiplayer games on WP. You can download the source from our GIT repo.

wp7 Develop realtime multiplayer games on WP8!

Screenshot of Tic Tac Toe running on Windows Phone 7

WP8 Develop realtime multiplayer games on WP8!

Screenshot of Tic Tac Toe running on Windws Phone 8

Follow these steps to get up and running.

1. Login/Sign-up on AppHQ (ShepHertz developer dashboard)

2. From the dashboard, create a new app of type appwarp cloud gaming.

3. Note its keys – you will require them to initialize the SDK in your code.

4. From the dashboard, create a new room with 2 max players. Note its room id – you will require this in your code.

5. Download the sample from GIT and setup the Visual Studio project.

6. In the project, add your keys and room id where indicated in the GlobalContext.cs file.

7. Debug/Run the application.

Please try this out and share your feedback with us on support@shephertz.com

Want to know more about developing on AppWarp?

AppWarp Overview

AppWarp WP Guide

You can also check out our App42 cloud apis to to publish and retrieve your games top score leader boards, send push notifications and much more!




3893cb46 e00d 48a3 ab37 ed895529743d Develop realtime multiplayer games on WP8!







58373e51 32a5 4e21 ac5a 38d4c3db8a3a Develop realtime multiplayer games on WP8!




Share it now
Be a fan!