CONNECTION_LOST is never triggered

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

Moderators: Lapo, Bax, MBagnati

steven
Posts: 19
Joined: 03 Dec 2012, 06:01

CONNECTION_LOST is never triggered

Postby steven » 15 Jul 2013, 07:47

hi,
i downloaded the latest version of C++ API(0.9.7) today, i want to make sure CONNECTION_LOST event is available, because we need to take care of the network problems.
so i ran the example code and tried to disable my LAN adapter.It was working fine for Windows environment. but in Mac it was not working.it depends on OS?

any suggestions?

best regards,
Steven
July 15,2013
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: CONNECTION_LOST is never triggered

Postby Bax » 15 Jul 2013, 08:01

Disabling the LAN adapter, just like unplugging the network cable, can cause unpredictable behaviors. This is not a surprise, because all active connections will not be closed: the reason is that in order to close connections you need to be able to communicate with the other end. If you abruptly unplug the network cable or disable the LAN adapter, such opportunity is not available.
A lingering connection will continue to exist for some time until the OS will trigger a timeout and shut them down. And this behavior can vary a lot between different operating systems, as you actually noted.
Anyway the right approach to test the connection lost event is using the KillConnection method available on the SmartFox class.
Paolo Bax
The SmartFoxServer Team
steven
Posts: 19
Joined: 03 Dec 2012, 06:01

Re: CONNECTION_LOST is never triggered

Postby steven » 15 Jul 2013, 08:26

hi Bax,
thanks for your quickly response.

another question is when i tried to reconnect to the server.
no response from the server in Mac.
in Windows i got an Visual C++ Runtime Library error like the following:
Assertion failed!
Program: ...
File: smartfox\sfs2x_api_cp...\shared_ptr.hpp
Line:424

Expression: px != 0


best regards,
Steven
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: CONNECTION_LOST is never triggered

Postby Bax » 15 Jul 2013, 08:28

Can you please post the exact steps you take?
Thanks.
Paolo Bax
The SmartFoxServer Team
steven
Posts: 19
Joined: 03 Dec 2012, 06:01

Re: CONNECTION_LOST is never triggered

Postby steven » 15 Jul 2013, 08:56

in Windows:
i firstly ran the client program of FullHouse and gave a wrong server IP to connect.
after a while, the CONNECTION event was triggered and show me the login dialog again, i put the correct server IP to reconnect, and then i got the error as the above.

in Mac:
everything is almost same in Windows environment. only difference is that after i gave a wrong IP to connect, it spent about 6 minutes to get CONNECTION triggered.


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

Re: CONNECTION_LOST is never triggered

Postby Lapo » 15 Jul 2013, 13:37

If you are pointing the server to a wrong port the BlueBox will take over once the OS will return a failure to connect.
Different OSes have different timeouts for socket connections. It sounds strange that it takes 6 minutes but it's still possible, especially if there's an active firewall between client and server.
Lapo
--
gotoAndPlay()
...addicted to flash games
steven
Posts: 19
Joined: 03 Dec 2012, 06:01

Re: CONNECTION_LOST is never triggered

Postby steven » 16 Jul 2013, 01:58

hi Lapo,

i have closed firewall for SFS. Well, let me take a check.
but, any idea or suggestions about the error i got when i tried to reconnect?

Steven,
July 16,2013
steven
Posts: 19
Joined: 03 Dec 2012, 06:01

Re: CONNECTION_LOST is never triggered

Postby steven » 16 Jul 2013, 02:45

steven wrote:hi Lapo,

i have closed firewall for SFS. Well, let me take a check.
but, any idea or suggestions about the error i got when i tried to reconnect?

Steven,
July 16,2013



just did another attempting:
1,firstly gave a correct IP and Port, it working fine.
2,wait a moment and did nothing, exceeding the user maximum idle time, the programm asked me to reconnect, and i clicked the "connect" button.
3,the UI show "Connecting to server" and no response at all.

i am not very familiar with c++, any ideas?

Steven
ganquan
Posts: 38
Joined: 17 Apr 2013, 01:42

Re: CONNECTION_LOST is never triggered

Postby ganquan » 16 Jul 2013, 10:11

the first time click connect, the client will call mSmartFox->Connect, and get the OnSmartFoxConnection called.
and the server log below:

Code: Select all

2013 | 17:10:47,956 | INFO | main | smartfoxserver.v2.SmartFoxServer | SmartFoxServer 2X (2.0.1) READY!
2013 | 17:10:57,372 | INFO | SocketReader | bitswarm.core.SocketAcceptor | Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 192.168.5.101:15645 } on Server port: 9933 <---> 15645
2013 | 17:10:59,592 | INFO | com.smartfoxserver.v2.controllers.SystemController-1 | v2.api.SFSApi | Login in, { Zone: fullhouse }, ( User Name: fullhouse_0, Id: 0, Priv: 0, Sess: 192.168.5.101:15645 )


after idle for a while, the client recieve OnSmartFoxConnectionLost, and show the reconnect dialog.
the server log below:

Code: Select all

2013 | 17:12:07,960 | INFO | SocketReader | bitswarm.sessions.DefaultSessionManager | Session removed: { Id: 1, Type: DEFAULT, Logged: Yes, IP: 192.168.5.101:15645 }
2013 | 17:12:07,960 | INFO | SocketReader | v2.entities.SFSZone | User: fullhouse_0 was disconnected.
2013 | 17:12:07,961 | INFO | SocketReader | v2.api.SFSApi | User disconnected: ( User Name: fullhouse_0, Id: 0, Priv: 0, Sess: 192.168.5.101:15645 )
2013 | 17:12:07,961 | INFO | SocketReader | bitswarm.core.SocketReader | Socket closed: java.nio.channels.SocketChannel[closed]


when click reconnect, the client will call mSmartFox->Connect again, but did not get any callback this time.
and the server log below:

Code: Select all

2013 | 17:12:15,883 | INFO | SocketReader | bitswarm.core.SocketAcceptor | Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 192.168.5.101:15675 } on Server port: 9933 <---> 15675
2013 | 17:13:07,959 | INFO | Scheduler1-thread-1 | bitswarm.sessions.DefaultSessionManager | Session removed: { Id: 2, Type: DEFAULT, Logged: No, IP: 192.168.5.101:15675 }


the session is created, but did not get the connect called, and without the connect called, the client will not send login.
after a while, server removed the session, but the client did not know it, still waiting for callback.

i will check again later.
ganquan
Posts: 38
Joined: 17 Apr 2013, 01:42

Re: CONNECTION_LOST is never triggered

Postby ganquan » 16 Jul 2013, 12:35

i add log in SmartFox::EnquenueEvent , print the evt->ToString.

when disconnect, EnquenueEvent receive "connectionLost [ null]" twice.

after click the reconnect, receive nothing,

but i try new mSmartFox and add event listener again after connect lost, it can receive the next connect callback. maybe something wrong when connection lost.
User avatar
Bax
Site Admin
Posts: 4609
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: CONNECTION_LOST is never triggered

Postby Bax » 16 Jul 2013, 13:41

Thank you to steven for reporting and ganquan for looking into it.
We will check the API behavior and let you know.
Paolo Bax
The SmartFoxServer Team
MBagnati
Posts: 126
Joined: 12 Feb 2013, 10:57

Re: CONNECTION_LOST is never triggered

Postby MBagnati » 19 Jul 2013, 14:28

Hello to everybody,
after have read the exchanged posts I have done some tests and I have discovered two things:
1) There is a bug in the API: the connection lost event is notified twice when connection is terminated for idle timeout. This error has been solved (thanks to steven and ganquan for the reporting) and will be deployed with next API version.
2) FullHouse example is able to complete with success the first connection and detect a subsequent network fall down.
After a network disconnection, it is not able to reconnect itself to SmartFox server.
I think that the reason of the mistake depends on how FullHouse initializes API library.
API instance is created

Code: Select all

(new Sfs2X::SmartFox(true))
only once in FullHouseServer::initServer method that is invoked at application startup.
When FullHouse asks for a network reconnection, it uses the same API instance that has handled the connection fall down.
By convention, API are throwaway; every time a connection is closed the API must be recreated.
So, I suggest to change FullHouse example in order to recreate API instance (calling again new Sfs2X::SmartFox) every time it wants retry the establishment of a network connection with SmartFox server

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 20 guests