C++ API v1.7.2 and SpaceWar example released

Post here your questions about the C++ API for SFS2X

Moderators: Lapo, Bax, MBagnati

User avatar
Bax
Site Admin
Posts: 4390
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

C++ API v1.7.2 and SpaceWar example released

Postby Bax » 19 Apr 2017, 14:46

We just released version 1.7.2 of the C++ API for SmartFoxServer 2X.
This release contains a number of fixes to issues reported by developers.
Check the release notes and download the new API on this page: http://www.smartfoxserver.com/download/sfs2x#p=client

We also just released a new version of our C++ examples package, available on this page: http://www.smartfoxserver.com/download/sfs2x#p=examples
The package now contains the Cocos2D-x porting of our SpaceWar demo game, for which a full tutorial is also available in our official documentation.
The game has been developed by Dang Hoang Tuan Anh after our "call to arms" (see this post: viewtopic.php?f=34&t=15891). It comes with the source code and full instructions to setup the development environment to deploy the game to multiple platforms (iOS, Android, Windows).
Paolo Bax
The SmartFoxServer Team
doananhtai
Posts: 3
Joined: 06 Jun 2017, 01:59

Re: C++ API v1.7.2 and SpaceWar example released

Postby doananhtai » 06 Jun 2017, 02:06

In this SpaceWar example
I found the ExtensionRequest cause the memory increase until "terminated due to memory issue"

I think the problem is "new SFSObject()" and "(new ExtensionRequest(..)" with down delete..,
but I cannot find the correct way to release them... the .reset() not effected.
User avatar
Lapo
Site Admin
Posts: 20113
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 06 Jun 2017, 07:03

Hi,
if I remember correctly the SFSObject passed to the ExtensionRequest(...) constructor is a boost:shared_ptr (a smart pointer). It shouldn't cause that problem. What makes you think the memory issue is caused by that?
Lapo
--
gotoAndPlay()
...addicted to flash games
doananhtai
Posts: 3
Joined: 06 Jun 2017, 01:59

Re: C++ API v1.7.2 and SpaceWar example released

Postby doananhtai » 06 Jun 2017, 08:57

//Call this 20 times a second
boost::shared_ptr<ISFSObject> params = boost::shared_ptr<ISFSObject>(new SFSObject());
boost::shared_ptr<ExtensionRequest> request(new ExtensionRequest(REQ_CODE, params, room));
ptrSmartFox->Send(request);

//the memory increase until "terminated due to memory issue"
I don't know how to fix it.
doananhtai
Posts: 3
Joined: 06 Jun 2017, 01:59

Re: C++ API v1.7.2 and SpaceWar example released

Postby doananhtai » 06 Jun 2017, 09:22

I had solved this problem

Not use boost in example (SpaceWar/client/extenal/boost)
I download boost1.64.0 instead

In SmartFoxClientAPi library project
HeaderSearch and LibrarySearch do not use [api_folder]/Core/BoostAsio/Unix... use the path of boost1.64.0

and..with the old boost the ~MyStruct() never touch..but the new (1.64.0) does.
struct MyStruct {
MyStruct() {
cocos2d::log("new");
}

~MyStruct() {
cocos2d::log("delete");
}
};
auto x = boost::shared_ptr<MyStruct>(new MyStruct());

Thanks for All.
User avatar
Lapo
Site Admin
Posts: 20113
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 06 Jun 2017, 10:07

Thanks for your feedback.
However I am not sure why changing the version of Boost would make a difference.

I have tested with the current API using this code:

Code: Select all

void SimpleConnector::fastExtensionCall()
{
    int sleepMicros = 10 * 1000; // 100 pps
   
    for (int i = 0; i < 30000; i++)
    {
        auto params = boost::shared_ptr<ISFSObject>(new SFSObject());
        auto extReq = boost::shared_ptr<ExtensionRequest>(new ExtensionRequest("echo", params));
   
        sfs->Send(extReq);
       
        if (i % 1000 == 0)
            cout << "Ext req sent :: " << i << endl;
       
        usleep(sleepMicros);
    }
    cout << "---- DONE ----" << endl;
}


This fires 100 packets per second to the server for a total of 30K packets. I see the memory growing because all allocations are done inside the function. In other words all pointers are allocated on the stack and won't go away until the function returns. The memory grows up to 12-13 MBytes and when the function is done it drops back down to 2MBytes, which seems to indicate there are no memory leaks.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
phongka
Posts: 2
Joined: 13 Jun 2017, 10:37

Re: C++ API v1.7.2 and SpaceWar example released

Postby phongka » 13 Jun 2017, 10:44

Bax wrote:We just released version 1.7.2 of the C++ API for SmartFoxServer 2X.
This release contains a number of fixes to issues reported by developers.
Check the release notes and download the new API on this page: http://www.smartfoxserver.com/download/sfs2x#p=client

We also just released a new version of our C++ examples package, available on this page: http://www.smartfoxserver.com/download/sfs2x#p=examples
The package now contains the Cocos2D-x porting of our SpaceWar demo game, for which a full tutorial is also available in our official documentation.
The game has been developed by Dang Hoang Tuan Anh after our "call to arms" (see this post: viewtopic.php?f=34&t=15891). It comes with the source code and full instructions to setup the development environment to deploy the game to multiple platforms (iOS, Android, Windows).


Hi Bax,

I'm trying to build SpaceWar project on iOS platform, I'm using xcode. But I don't see SmartFoxClientApi project for Xcode (I use the new API: SFS2X_API_Cpp_v1.7.3). Please help to check this case. Thanks.
User avatar
Lapo
Site Admin
Posts: 20113
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 13 Jun 2017, 14:12

Hi,
the API are not provided with the example. Make sure to follow the build instructions here:
http://docs2x.smartfoxserver.com/ExamplesCpp/spacewar

If you have already built the API for iOS you will need to add them to the project together with the relative header files and dependencies.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
phongka
Posts: 2
Joined: 13 Jun 2017, 10:37

Re: C++ API v1.7.2 and SpaceWar example released

Postby phongka » 14 Jun 2017, 02:31

Lapo wrote:Hi,
the API are not provided with the example. Make sure to follow the build instructions here:
http://docs2x.smartfoxserver.com/ExamplesCpp/spacewar

If you have already built the API for iOS you will need to add them to the project together with the relative header files and dependencies.

cheers


Hi,

But I can not download the API in the above site (detail in attached file).
Attachments
Screen Shot 2017-06-14 at 9.34.58 AM.png
(242.68 KiB) Not downloaded yet
User avatar
Bax
Site Admin
Posts: 4390
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: C++ API v1.7.2 and SpaceWar example released

Postby Bax » 14 Jun 2017, 06:55

Sorry, the link was missing, now it is fixed.
Anyway you can get the C++ API here: http://www.smartfoxserver.com/download/sfs2x#p=client
Paolo Bax
The SmartFoxServer Team
hungphung33
Posts: 4
Joined: 26 Dec 2017, 08:26

Re: C++ API v1.7.2 and SpaceWar example released

Postby hungphung33 » 26 Dec 2017, 08:44

sorry guy, i try to setup a project on window using vs2013 and SFS2X_API_Cpp_v1.7.4

Code: Select all

m_ptrSmartFox = boost::shared_ptr<Sfs2X::SmartFox>(new Sfs2X::SmartFox(true));
   m_ptrSmartFox->ThreadSafeMode(false);
   
   m_ptrSmartFox->AddEventListener(SFSEvent::CONFIG_LOAD_SUCCESS, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(HelloWorld::OnloadConfigSucces, (unsigned long long)this)));
   m_ptrSmartFox->AddEventListener(SFSEvent::CONNECTION, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(HelloWorld::OnSmartFoxConnection, (unsigned long long)this)));
   m_ptrSmartFox->AddEventListener(SFSEvent::CONNECTION_LOST, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(HelloWorld::OnSmartFoxConnectionLost, (unsigned long long)this)));
   m_ptrSmartFox->AddEventListener(BitSwarmEvent::DISCONNECT, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(HelloWorld::OnSmartFoxDisconnection, (unsigned long long)this)));
   
   m_ptrSmartFox->Connect("127.0.0.1", 9933);


but i got error :

Code: Select all

Program: ...SmartFox\SmartFoxTest\proj.win32\Debug.win32\SmartFoxTest.exe
File: f:\dd\vctools\crt\crtw32\misc\dbgdel.cpp
Line: 52

Expression: _BLOCK_TYPE_IS_VALID(pHead->nBlockUse)


can some one help me setup
User avatar
Lapo
Site Admin
Posts: 20113
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 26 Dec 2017, 18:30

Hi,
very difficult what might be wrong. Seems like an issue specific with VS2013 which is quite old.
Did you use the instructions provided here?
http://docs2x.smartfoxserver.com/Gettin ... cpp-vs2013
and changed the references to compiler 10.0 to 12.0?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
hungphung33
Posts: 4
Joined: 26 Dec 2017, 08:26

Re: C++ API v1.7.2 and SpaceWar example released

Postby hungphung33 » 29 Dec 2017, 15:16

Lapo wrote:Hi,
very difficult what might be wrong. Seems like an issue specific with VS2013 which is quite old.
Did you use the instructions provided here?
http://docs2x.smartfoxserver.com/Gettin ... cpp-vs2013
and changed the references to compiler 10.0 to 12.0?

Thanks


thank Lapo, i think error because vs2013 too old, so i setup vs2015,
but in "Building the static libraries" step, i build debug static x64 success, but i got error when build release static

Code: Select all

LINK : fatal error LNK1181: cannot open input file 'zlibstat.lib'


can u help me fix it :(
hungphung33
Posts: 4
Joined: 26 Dec 2017, 08:26

Re: C++ API v1.7.2 and SpaceWar example released

Postby hungphung33 » 30 Dec 2017, 06:57

hi Lapo, sorry because 1st time use vs 2015, i builded library, but after config client project and build debug i got error:

Code: Select all

error LNK2001: unresolved external symbol "class boost::system::error_category const & __cdecl boost::system::generic_category(void)"
error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall Sfs2X::SmartFox::SmartFox(bool)"
error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall Sfs2X::SmartFox::~SmartFox(void)"
....
fatal error LNK1120: 14 unresolved externals

can u help me fix this?
User avatar
Lapo
Site Admin
Posts: 20113
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: C++ API v1.7.2 and SpaceWar example released

Postby Lapo » 30 Dec 2017, 08:41

It looks like you haven't setup the linker paths correctly, so the compiler can't link some of the necessary libraries.
I would highly recommend to go back to the step-by-step guide here:
http://docs2x.smartfoxserver.com/Gettin ... studio2015

and double check that the linker paths are setup correctly.
In particular make sure you're using quotations around your paths to avoid issues with spaces. Read here for more:
https://support.microsoft.com/en-us/hel ... ld-a-manag

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 1 guest