Tag Archives: sfs2x

HTML5 / JavaScript tutorials

We just published the first batch of HTML5 / JavaScript tutorials describing the following examples in details:

  • Connector
    Learn how to configure the client and make your first connection
  • Simple Chat
    Learn how to create a basic chat environment for connected users
  • Advanced Chat
    Learn how to create a complete browser-based chat application featuring public chat messaging, Rooms management, private chat messaging and more
  • Game Lobby
    Learn how to create a “lobby” application where users can meet and invite each other to play games

All tutorials are available in our documentation website.

Using the geolocation API

The following instructions are valid for al SFS2X prior to version 2.12. See the last section at the bottom for more recent releases.

SmartFoxServer 2X comes with a geolocation API and database that are used mainly in the AdminTool’s Analytics module to aggregate and show statistics based on geographical positions. The API is not directly exposed to developers but since it’s been requested several times here is a quick recipe on how to use geolocation in your Extension code.

For starters we need to add lib/logs-analysis-app.jar to our project’s dependencies and import a couple of classes:

import com.maxmind.geoip.Country;
import com.smartfoxserver.v2.admin.utils.IpGeoLocator;

NOTE: starting from SmartFoxServer 2X v2.12, the com.maxmind.geoip.Country class has been replaced by com.maxmind.geoip2.record.Country; change the above import accordingly.

Next we instantiate and initialize the IpGeoLocator class:

IpGeoLocator geo = new IpGeoLocator();
geo.init("data/", false);

This tells the geolocation service to load the relative database, located under SFS2X/data/. Finally we can test the service with an IP address:

String ipAdr = "208.80.154.224"; // wikipedia's IP

// Locate address
Country country = geo.locateIP(adr);

if (country == null)
   System.out.println("Not found for address: " + ipAdr);
else
   System.out.println(ipAdr + ": " + countrt.getName() + ", " + country.getCode();

Running the code results in this output:

208.80.154.224: United States, US

NOTE: it is important to always check that the returned Country object is not null. If it is, the geolocation service was not able to resolve the IP to a specific country.

» SFS2X 2.12.x and higher

SFS2X 2.12 introduced automatic geolocation for every client. The setting is configurable per-Zone from the AdminTool > Zone Configurator > Enable Geolocation.

When the service is active we can access the geolocation data with a few lines of server side code:

import com.smartfoxserver.v2.util.Country;

class MyHandler extends BaseClientRequestHandler
{
	void handleClientRequest(User sender, ISFSObject params)
	{
		Country ctry = sender.getCountry();
		
		if (ctry != null)
		{
			trace("User's country: " + ctry.getName());
			trace("Country ISO code: " + ctry.getIsoCode());
		}
	}
}

 

An App, a Marathon and an Astronaut: a SFS case story

Over the last few years, the RunSocial mobile app has been under development featuring SmartFoxServer 2X and other innovative technologies. Recently, the app was approved by the American National Aeronautics and Space Administration (NASA) and the European Space Agency (ESA) for use on the International Space Station (ISS).

On April 24th 2016, Tim Peake of the European Space Agency completed the London Marathon, running the 42.2 km on a treadmill connected to RunSocial while circling the Earth about two and half times at an altitude of 400 km high, being visible to all other virtual concurrent runners.

SmartFoxServer proved to be a mature and robust solution for this task, thanks to its high performance and scalable messaging system in multi-user, realtime scenarios, a sensible structure for organizing application logic and a wide range of options to store, organize, and distribute users and data.

Read the full story!