• Examples (iOS)
• Examples (Android)
• Examples (C++)
Server API Documentation

 

» Client API setup | C++

The C++ API is used to develop applications and games for a large number of platforms (mobile devices, game consoles, etc).
It is distributed as a set of source files: part of these files must be compiled to generate libraries that will be referenced by the client application; others will be included in your project as method prototypes.
Unzip the provided archive to a folder of your choice (referenced later as [api_folder]) and follow the next instructions.

Choose your operating system and development environment:

» Windows — Visual Studio 2010

» Libraries compilation

To compile the required libraries you need Microsoft Visual Studio 2010 SP1 to be installed on your computer.

Open a Windows Command Prompt on the file system path [api_folder]\Core\BoostAsio\Windows; type in bootstrap and wait for command execution.

When completed, type in one-by-one the follow commands:

> b2 -a toolset=msvc-10.0 threading=multi link=static runtime-link=shared --with-system stage
> b2 -a toolset=msvc-10.0 threading=multi link=static runtime-link=shared --with-date_time stage
> b2 -a toolset=msvc-10.0 threading=multi link=static runtime-link=shared --with-chrono stage
> b2 -a toolset=msvc-10.0 threading=multi link=static runtime-link=shared --with-regex stage
> b2 -a toolset=msvc-10.0 threading=multi link=static runtime-link=shared --with-thread stage

If all has been done with success, you will find out that a new directory named [api_folder]\Core\BoostAsio\Windows\stage\lib has been created, containing ten .lib files.
The Windows Command Prompt can now be closed.

Start Microsoft Visual Studio 2010 and open the solution SmartFoxClientApi contained in [api_folder]\SmartFoxClientApi\VS2010.

Perform a Rebuild Solution for both Debug and Release configurations.The SmartFoxClientApi solution can then be closed.

» Project configuration

Move to the project settings of your Microsoft Visual Studio 2010 client application. Select General options into the C/C++ section and add the [api_folder]\Core\BoostAsio\Windows path to the Additional Include Directories for both Debug and Release configurations.

Now select General options into the Linker section.
Add the [api_folder]\Core\BoostAsio\Windows\stage\lib path to Additional Library Directories for both Debug and Release configurations.
Add the [api_folder]\Deploy\VisualStudio2010\Debug path to Additional Library Directories for Debug configurations.
Add the [api_folder]\Deploy\VisualStudio2010\Release path to Additional Library Directories for Release configurations.

Select Input options into the Linker section and add SmartFoxClientApi.lib to Additional Dependancies for both Debug and Release configurations.

You can now start using the SmartFoxServer 2X API in your project.

» Windows — Visual Studio 2012

Please refer to the Visual Studio 2010 instructions, replacing all references to VS2010 with VS2012 and the version of the compiler from 10.0 to 11.0.

» Windows — Visual Studio 2013

Please refer to the Visual Studio 2010 instructions, replacing all references to VS2010 with VS2013 and the version of the compiler from 10.0 to 12.0.

» Windows — Visual Studio 2015

Please refer to the Visual Studio 2010 instructions, replacing all references to VS2010 with VS2015 and the version of the compiler from 10.0 to 14.0.

To build the SmartFoxServer API you will need the C++ compiler. As Visual Studio 2015 doesn't install C++ by default, you have to re-run its setup, select Modify and then check Programming Language -> C++.

» Windows — Eclipse Cygwin

» Libraries compilation

To compile the required libraries you need Eclipse with C/C++ Development Tools and Cygwin installed on your computer.

Run Cygwin package installer to add SSL support. Installer is available at https://cygwin.com/install.html Execute setup-x86.exe or setup-x64.exe according with your operating system and use search feature to look for openssl and openssl-devel packages.

Add cygwin\bin to the system path and run Cygwin Terminal (see Windows Start\Programs menu).

In the Cygwin Terminal shell type the following command (use the proper path) to move to the [api_folder]\Core\BoostAsio\Unix folder.

> cd /cygdrive/c/.../[api_folder]/Core/BoostAsio/Unix

Now type in:

> ./bootstrap.sh –prefix=boost/

and wait for the command execution. When completed, type in:

> ./b2

If all has been done with success, you will find out that a new directory named [api_folder]\Core\BoostAsio\Unix\stage\lib has been created, containing five .dll files.
The Cygwin Terminal can now be closed.

» API compilation

Start Eclipse and choose File > New > Project from its menu. In the New Project wizard dialog, choose C++ Project from C/C++ section, than press Next.

In the C++ Project dialog:

then press Finish.

Eclipse will create the SmartFoxServer2X C++ API project. Answer Yes when is asked to open the C/C++ perspective.

In the Project Explorer panel, perform the following exclusions (to do it, right-click on the project node and select Resource configuration > Exclude from build in the popup menu):

Enter the Project settings panel and apply the following changes to C/C++ Build > Settings > Tool Settings:

Finally, select the menu item Project > Build project to perform a rebuild and generate the SmartFoxClientApi.dll library.

» Project configuration

This paragraph applies if you use Eclipse as development environment for your C++ application/game. If not, please check the documentation of your environment of choice on how to import external libraries.

In Eclipse, move to the project settings of your Eclipse client application. Select Preprocessor options under Cygwin C++ Compiler and add __USE_W32_SOCKETS to the Defined symbols for both Debug and Release configurations.

Now select Includes settings and add a reference to [api_folder]\Core\BoostAsio\Unix path, always for both Debug and Release configurations.

Finally move to the Libraries settings of Cygwin C++ Linker to add the [api_folder]\Core\BoostAsio\Unix\stage\lib path and the output directory where the previously compiled API was deployed. Also add ws2_32, boost_system andSmartFoxClientApi as application libraries. Perform these steps for both Debug and Release configurations.

You can now start using the SmartFoxServer 2X API in you project.

» Linux/Unix — Eclipse

» Libraries compilation

To compile the required libraries you need Eclipse with C/C++ Development Tools and g++ installed on your computer.

For example, to install g++ on Ubuntu Linux, open a Terminal shell and type the command:

$ sudo apt-get install build-essential g++

You should get the following output:

For other platforms please referer to their documentation.

C++ API needs of Boost and OpenSSL libraries. These are open source packages that can be installed and built by following commands.

In the Terminal shell type in:

$ sudo apt-get install libssl-dev

Then type the following command (use the proper path) to move to the [api_folder]/Core/BoostAsio/Unix folder.

$ cd .../[api_folder]/Core/BoostAsio/Unix

Now type in:

$ chmod -R a+rwx+X ./

and:

$ ./bootstrap.sh –prefix=boost/

and wait for the command execution. When completed, type in:

$ ./b2

You should get the following output:

If all has been done with success, you will find out that a new directory named [api_folder]/Core/BoostAsio/Unix/stage/lib has been created, containing six .a files.

The shell can now be closed.

» API compilation

Start Eclipse and choose File > New > Project from its menu. In the New Project wizard dialog, choose C++ Project from C/C++ section, than press Next.

In the C++ Project dialog:

Then press Next in all the dialogs until the Finish button is displayed, and press it.

Eclipse will create the SmartFoxServer2X C++ API project.

In the Project Explorer panel, perform the following exclusions (to do it, right-click on the project node and select Resource configuration > Exclude from build or Properties in the popup menu):

Enter the Project settings panel and apply the following changes to C/C++ Build > Settings:

Finally, select the menu item Project > Build project to perform a rebuild and generate the SmartFoxClientApi library.

» Project configuration

This paragraph applies if you use Eclipse as development environment for your C++ application/game. If not, please check the documentation of your environment of choice on how to import external libraries.

In Eclipse, move to the project settings of your Eclipse client application. Select Includes under Cross G++ Compiler and add a reference to [api_folder]/Core/BoostAsio/Unix path for both Debug and Release configurations.

Finally move to the Libraries settings ofCross G++ Linker to add the [api_folder]/Core/BoostAsio/Unix/stage/lib path and the output directory where the previously compiled API was deployed. Also addboost_system, pthread and SmartFoxClientApi as application libraries. Perform these steps for both Debug and Release configurations.

You can now start using the SmartFoxServer 2X API in you project.

» Mac OS X — Xcode 7 and higher

» Libraries compilation

To compile the required libraries, please check that you are using at least the release 1.59 of Boost.

Launch a Terminal on the file system path [api_folder]/Core/BoostAsio/Unix and type in the command chmod -R a+rwx+X ./

Now type in: ./bootstrap.sh –prefix=boost/ and wait for the command execution.

When completed, type in: ./b2

If all has been done with success, you will find out that a new directory named [api_folder]/Core/BoostAsio/Unix/stage/lib has been created, containing the built libraries.

The Terminal can now be closed.

Start Xcode and create an OS X Dynamic Library project for STL C++

Add all SmartFox API folders and files to the created project.



Now remove the Core/BoostAsio, Core/OpenSSL and ZLib references from the project (NOTE: just remove the references, do not the delete the actual folders)


This is what the project view should look like after having removed the three items in the previous step:

Under Build Settings:

 

NOTE: the position of the openssl library depends on the package manager used to install on your Mac. You can use Brew or MacPorts to setup the latest OpenSSL libraries. Then make sure to reference the correct path based on the location used by the tool of your choice.

Alternatively you can download the OpenSSL sources from the official website and compile it.
Firstly decompress the archive, open a terminal in the unpacked folder and type:

  • sudo mkdir -p /usr/local/openssl-1.0.2k
  • ./Configure darwin64-x86_64-cc --prefix=/usr/local/openssl-1.0.2k
  • make
  • sudo make install

Add the following paths to the Prelink libraries menu

Set Perform Single-Object Prelink to Yes.
Set Other Linker Flags to -lz.

You can now build the SmartFoxServer 2X API and use it in your project.

» iOS — Xcode 7 and higher

» Libraries compilation

To compile the required libraries, please check that you are using at least the release 1.59 of Boost.

Launch a Terminal on the file system path [api_folder]/Core/BoostAsio/Unix and type in the command chmod -R a+rwx+X ./

Now type in: ./bootstrap.sh –prefix=boost/ and wait for the command execution.

When completed, type in: ./b2

If all has been done with success, you will find out that a new directory named [api_folder]/Core/BoostAsio/Unix/stage/lib has been created, containing the built libraries.

The Terminal can now be closed.

The client API needs of OpenSSL library.
Please note that if you are working on a Mac computer based on OS X El Capitan, Apple has removed the OpenSSL header files.
This change in OS X makes it hard to build OpenSSL-dependent projects.
In OS X El Capitan you can get OpenSSL library from official website looking for version 1.0.2 in download section.
Note that OpenSSL project has delivered since 2016 newest versions of the library like the version 1.1.0. Do not use versions greater than 1.0.2 because they are not compatible with Boost Library 1.59 used from client API.

Launch a Terminal to uncompress the archive got from OpenSSL website by command
tar -xvzf openssl-1.0.2h.tar.gz

Then move into created folder and type in
./Configure darwin64-x86_64-cc -shared

When completed, type in:
make

If all has been done with success, you will find out the built libraries libcrypto.a and libssl.a

The Terminal can now be closed.

Launch Xcode, and choose File\New\Project.
When the "Choose a template" dialog appears, select iOS\Framework & Library\Cocoa Touch Static Library and create an iOS Cocoa Touch Static Library project for STL C++

Add all SmartFox API folders and files to created project.
Leave only SmartFox API source files in Targets->Build Phases->Compile Sources.
Leave only Boost libraries in Targets->Build Phases->Link Binary With Libraries.

Set Preprocessor Macro to SMARTFOXCLIENTAPI_EXPORTS.
Set Preprocessor Macro to BOOST_THREAD_PROVIDES_FUTURE.

Disable the usage of precompiled headers.
Set Header Search Paths to [api_folder]/Core/BoostAsio/Unix.
Set Header Search Paths to [openssl_folder]/include.

Set Library Search Paths to [api_folder]/Core/BoostAsio/Unix/stage/lib,
Set Library Search Paths to [openssl_folder].

Set Prelink libraries to [openssl_folder]/libcrypto.a.
Set Prelink libraries to [openssl_folder]/libssl.a.
Set Prelink libraries to [api_folder]/Core/BoostAsio/Unix/stage/lib/libboost_thread.a.
Set Prelink libraries to [api_folder]/Core/BoostAsio/Unix/stage/lib/libboost_system.a.
Set Perform Single-Object Prelink to Yes.
Set Other Linker Flags to -lz.

You can now build the SmartFoxServer 2X API and use it in your project.

 

« back to client API list