Can not retry connection in C++ API

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

Moderators: Lapo, Bax, MBagnati

errusteven
Posts: 4
Joined: 24 Jul 2014, 03:52

Can not retry connection in C++ API

Postby errusteven » 24 Jul 2014, 10:48

Hi Bax and Lapo
I use KillConnection function of Smartfox class to test the reconnection system. The event USER_RECONNECTION_TRY has been fired in server side, but in client side there is no event such as SFSEvent::CONNECTION_RETRY or SFSEvent::CONNECTION_RESUME has fired. I don't know how to fix it and wonder "Does C++ API support reconnection in 1.1.2 version?". Hope you will help me to fix this problem.

Thanks
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can not retry connection in C++ API

Postby Lapo » 28 Jul 2014, 17:49

Hi,
they are implemented.
Can you just tell me what is the setting for the "User reconnection time" in your Zone?

Also how do you test the disconnection?

thanks
Lapo
--
gotoAndPlay()
...addicted to flash games
errusteven
Posts: 4
Joined: 24 Jul 2014, 03:52

Re: Can not retry connection in C++ API

Postby errusteven » 29 Jul 2014, 05:54

Hi

The "User reconnection time" that I use in server config is 30 seconds.

In Client, I add 2 events: SFSEvent::CONNECTION_RETRY and SFSEvent::CONNECTION_RESUME
void CasinoServer::initServer()
{
// Initialize Smart Fox
mSmartFox = boost::shared_ptr<Sfs2X::SmartFox>(new Sfs2X::SmartFox(true));
mSmartFox->ThreadSafeMode(true);

// Add event listeners
mSmartFox->AddEventListener(SFSEvent::CONNECTION_RETRY, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(CasinoServer::OnSmartFoxConnectionRetry, (unsigned long long)this)));
mSmartFox->AddEventListener(SFSEvent::CONNECTION_RESUME, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(CasinoServer::OnSmartFoxConnectionResume, (unsigned long long)this)));
}

void CasinoServer::OnSmartFoxConnectionRetry(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent)
{
CCLog("Retry");
}

void CasinoServer::OnSmartFoxConnectionResume(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent)
{
CCLog("Resume");
}

And then I use KillConnection function to test: mSmartFox->KillConnection();
But I do not see any thing such as Retry or Resume in console


In server, I add 2 events as client in my extension

public void init(){
this.addEventHandler(SFSEventType.USER_RECONNECTION_TRY, OnUserReconnectionTry.class);
this.addEventHandler(SFSEventType.USER_RECONNECTION_SUCCESS, OnUserReconnectionSuccess.class);
}

public class OnUserReconnectionTry extends BaseServerEventHandler {
public void handleServerEvent(ISFSEvent event) throws SFSException {
//Log Retry connection
}
}

public class OnUserReconnectionSuccess extends BaseServerEventHandler {
public void handleServerEvent(ISFSEvent event) throws SFSException {
//Log Reconnection success
}
}

When I kill connection, I only see "Retry connection log" in server, but "Reconnection success log" is not
I dont know I have missed something when I implement

Thanks
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Can not retry connection in C++ API

Postby Lapo » 29 Jul 2014, 07:57

Thanks. We'll investigate and get back to you.
Lapo

--

gotoAndPlay()

...addicted to flash games
errusteven
Posts: 4
Joined: 24 Jul 2014, 03:52

Re: Can not retry connection in C++ API

Postby errusteven » 29 Jul 2014, 09:43

Hi Lapo, I found strange thing in SmartFox.cpp

// -------------------------------------------------------------------
// OnSocketClose
// -------------------------------------------------------------------
void SmartFox::OnSocketClose(unsigned long long context, boost::shared_ptr<BaseEvent> e)
{
SmartFox* instance = (SmartFox*)context;
boost::shared_ptr<BitSwarmEvent> evt = (boost::static_pointer_cast<BitSwarmEvent>)(e);
instance->Reset();

// Fire event
boost::shared_ptr<map<string, boost::shared_ptr<void> > > data (new map<string, boost::shared_ptr<void> >());
data->insert(pair<string, boost::shared_ptr<void> >("reason", (*(evt->Params()))["reason"]));
boost::shared_ptr<BaseEvent> sfsEvt (new SFSEvent(SFSEvent::CONNECTION_LOST, data));
instance->DispatchEvent(sfsEvt);
}

// -------------------------------------------------------------------
// OnSocketReconnectionTry
// -------------------------------------------------------------------
void SmartFox::OnSocketReconnectionTry(unsigned long long context, boost::shared_ptr<BaseEvent> e)
{
SmartFox* instance = (SmartFox*)context;

// Fire event
boost::shared_ptr<BaseEvent> sfsEvt (new SFSEvent(SFSEvent::CONNECTION_RETRY));
}

At OnSocketReconnectionTry function. It have not this line: instance->DispatchEvent(sfsEvt);
MBagnati
Posts: 126
Joined: 12 Feb 2013, 10:57

Re: Can not retry connection in C++ API

Postby MBagnati » 30 Jul 2014, 09:01

Hi,
You are right, function OnSocketReconnectionTry does not fire up the CONNECTION_RETRY event because the DispatchEvent statement is missing.
But I think that this is not the only reason that causes the error. I suspects that the error cause is little more extended.
I am working to fix the problem.
I am apologize for the error, I think to give you a fix in a little time

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 44 guests