Impossible to get an UDP connection

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

Moderators: Lapo, Bax, MBagnati

ffelagund
Posts: 6
Joined: 19 Nov 2018, 08:09

Impossible to get an UDP connection

Postby ffelagund » 14 Jan 2019, 12:45

Hello,

I'm trying to get an UDP connection following the steps that I've found in the docs, but I'm unable to.
Here is what I did:
a) I've set up the server in the Admin Tool for listening to the address 0.0.0.0:9933 (TCP) and 0.0.0.0:9999 (UDP)
b) I've successfully compiled and got a normal TCP connection in the SpaceWar demo.
c) Following the documentation steps, I've added the following line just after the LOGIN one:
getSmartFox()->AddEventListener(SFSEvent::UDP_INIT, boost::shared_ptr<EventListenerDelegate> (new EventListenerDelegate(LoginScene::onUDPInit, (unsigned long long)this))); and wrote a simple onUDPInit function that just checks the operation status.
d) Called InitUD(); (no parameters) in the onLogin callback
e) In the ServerConnector I wrote the following code (replacing m_smartFoxServer->Connect("127.0.0.1, 9933);):

Code: Select all

boost::shared_ptr<Sfs2X::Util::ConfigData> data(new Sfs2X::Util::ConfigData);
   #define SERVER_IP "192.168.0.154"
   //#define SERVER_IP "127.0.0.1"
   data->Host(SERVER_IP);
   data->Port(9933);
   data->UdpHost(SERVER_IP);
   data->UdpPort(9999);
   data->Debug(true);
   data->Zone("SpaceWar");
   m_smartFoxServer->Connect(data);


Server's log for the loging attempt that is failing is the following:

Code: Select all

14:04:00,660 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 192.168.0.89:51397 } on Server port: 9933 <---> 51397
14:04:05,412 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: SpaceWar }, ( User Name: 36, Id: 1, Priv: 0, Sess: 192.168.0.89:51397 ) , Type: C++ API


My Smartfox server is running on a linux machine and in the same network. No fiweralls neither proxies are between the client and the server.

What is happening is that inside the InitUDP, the operation takes ages (say minutes) and sometimes the process ends with a stack overflow crash, or the server drops the session

Code: Select all

14:06:11,886 INFO  [SocketReader] sessions.DefaultSessionManager     - Session removed: { Id: 2, Type: DEFAULT, Logged: Yes, IP: 192.168.0.89:51397 }
14:06:11,887 INFO  [SFSWorker:Sys:1] api.SFSApi     - User disconnected: { Zone: SpaceWar }, ( User Name: 36, Id: 1, Priv: 0, Sess: 192.168.0.89:51397 ) , SessionLen: 126475, Type: C++ API


I've checked the server logs and it seems that the udp socket is connectly bound, so I have no clue about what I could be doing wrong.

Any help would be appreciated.
Thanks!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Impossible to get an UDP connection

Postby Lapo » 14 Jan 2019, 14:11

Hello,
Server's log for the loging attempt that is failing is the following:

Code: Select all

14:04:00,660 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 192.168.0.89:51397 } on Server port: 9933 <---> 51397
14:04:05,412 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: SpaceWar }, ( User Name: 36, Id: 1, Priv: 0, Sess: 192.168.0.89:51397 ) , Type: C++ API


the logs you have reported don't seem to indicate any failures. If the UDP connection fails you will see it from client side, in the SFSEvent.UDP_INIT.

It sounds pretty strange that it's taking so long for the connection in a local network. The long time actually suggests a firewall in between, even if you reported there should be none.

To check your network is fine I suggest this test:

1) stop SFS2X
2) on the Linux machine running SFS2X execute this -> nc -ul 9999 (listens on UDP 9999)
3) on the client machine run this command -> echo -n "Hello World" >/dev/udp/<server-ip>/9999

You should immediately receive the "Hello World" message on the Linux box.

Let us know.
Lapo
--
gotoAndPlay()
...addicted to flash games
ffelagund
Posts: 6
Joined: 19 Nov 2018, 08:09

Re: Impossible to get an UDP connection

Postby ffelagund » 14 Jan 2019, 14:50

Just to make things cleaner and easier to diagnose, I've just configured a local Smartfox server. Server side I got the same logs:

Code: Select all

15:28:56,184 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: SpaceWar }, [ MMORoom: Sol, Id: 1, Group: default, AOI: (900, 750, 0) ], type = MMORoom
15:28:56,226 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: --=={{{ AdminZone }}}==-- }, [ Room: AdminRoom, Id: 2, Group: default, isGame: false ], type = SFSRoom
15:28:56,248 INFO  [main] core.AdminToolService     - AdminTool Service started
15:28:56,375 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - Listening Sockets: { 0.0.0.0:9933, (Tcp) } { 0.0.0.0:9999, (Udp) }
15:28:56,375 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     -
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_|
[ 2.13.0 ]

15:28:56,376 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - SmartFoxServer 2X (2.13.0) READY!
15:28:56,932 INFO  [main] v3.SessionFilter     - BlueBox-2X Service (3.1.0) READY.
15:29:44,921 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 0:0:0:0:0:0:0:1:53571 } on Server port: 9933 <---> 53571
15:29:44,940 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: --=={{{ AdminZone }}}==-- }, ( User Name: sfsadmin, Id: 0, Priv: 0, Sess: 0:0:0:0:0:0:0:1:53571 ) , Type: Flash ActiveX:WIN 32,0,0,114
15:29:44,944 INFO  [SFSWorker:Ext:4] api.SFSApi     - Room joined: [ Room: AdminRoom, Id: 2, Group: default, isGame: false ], { Zone: --=={{{ AdminZone }}}==-- }, ( User Name: sfsadmin, Id: 0, Priv: 0, Sess: 0:0:0:0:0:0:0:1:53571 ) , asSpect: false
15:30:16,877 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 127.0.0.1:53582 } on Server port: 9933 <---> 53582
15:30:20,824 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: SpaceWar }, ( User Name: hhhj, Id: 1, Priv: 0, Sess: 127.0.0.1:53582 ) , Type: C++ API
15:32:26,545 INFO  [SocketReader] sessions.DefaultSessionManager     - Session removed: { Id: 2, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:53582 }
15:32:26,545 INFO  [SFSWorker:Sys:4] api.SFSApi     - User disconnected: { Zone: SpaceWar }, ( User Name: hhhj, Id: 1, Priv: 0, Sess: 127.0.0.1:53582 ) , SessionLen: 125721, Type: C++ API


Client side, I still have a crash, in a different part of the code but always inside InitUDP. This is the callstack

Code: Select all

    ucrtbased.dll!0fa134d6()   Unknown
    [Frames below may be incorrect and/or missing, no symbols loaded for ucrtbased.dll]   Unknown
    ucrtbased.dll!0fa13324()   Unknown
    ucrtbased.dll!0fa1528a()   Unknown
    SmartFoxClientApi.dll!boost::shared_ptr<Sfs2X::Entities::User>::operator->() Line 687   C++
    SmartFoxClientApi.dll!Sfs2X::Bitswarm::UDPManager::SendInitializationRequest() Line 331   C++
    SmartFoxClientApi.dll!Sfs2X::Bitswarm::UDPManager::OnTimeout(const boost::system::error_code & code={...}) Line 388   C++
    SmartFoxClientApi.dll!boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>::operator()(Sfs2X::Bitswarm::UDPManager * p=0x001aba08, const boost::system::error_code & a1={...}) Line 165   C++
    SmartFoxClientApi.dll!boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> >::operator()<boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list1<boost::system::error_code const &> >(boost::_bi::type<void> __formal={...}, boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &> & f={...}, boost::_bi::list1<boost::system::error_code const &> & a={...}, int __formal=0) Line 316   C++
    SmartFoxClientApi.dll!boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >::operator()<boost::system::error_code const &>(const boost::system::error_code & a1={...}) Line 908   C++
    SmartFoxClientApi.dll!boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code>::operator()() Line 48   C++
    SmartFoxClientApi.dll!boost::asio::asio_handler_invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code> >(boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code> & function={...}, ...) Line 70   C++
    SmartFoxClientApi.dll!boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code>,boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > > >(boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code> & function={...}, boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > > & context={...}) Line 37   C++
    SmartFoxClientApi.dll!boost::asio::detail::wait_handler<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > > >::do_complete(boost::asio::detail::win_iocp_io_service * owner=0x04abd4c0, boost::asio::detail::win_iocp_operation * base=0x1061e088, const boost::system::error_code & __formal={...}, unsigned int __formal=0) Line 70   C++
    SmartFoxClientApi.dll!boost::asio::detail::win_iocp_operation::complete(boost::asio::detail::win_iocp_io_service & owner={...}, const boost::system::error_code & ec={...}, unsigned int bytes_transferred=0) Line 46   C++
    SmartFoxClientApi.dll!boost::asio::detail::win_iocp_io_service::do_one(bool block=true, boost::system::error_code & ec={...}) Line 406   C++
    SmartFoxClientApi.dll!boost::asio::detail::win_iocp_io_service::run(boost::system::error_code & ec={...}) Line 164   C++
    SmartFoxClientApi.dll!boost::asio::io_service::run() Line 59   C++
    SmartFoxClientApi.dll!Sfs2X::Bitswarm::UDPManager::StartTimer() Line 413   C++
    SmartFoxClientApi.dll!Sfs2X::Bitswarm::UDPManager::OnTimeout(const boost::system::error_code & code={...}) Line 389   C++
    SmartFoxClientApi.dll!boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>::operator()(Sfs2X::Bitswarm::UDPManager * p=0x001aba08, const boost::system::error_code & a1={...}) Line 165   C++
    SmartFoxClientApi.dll!boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> >::operator()<boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list1<boost::system::error_code const &> >(boost::_bi::type<void> __formal={...}, boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &> & f={...}, boost::_bi::list1<boost::system::error_code const &> & a={...}, int __formal=0) Line 316   C++
    SmartFoxClientApi.dll!boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >::operator()<boost::system::error_code const &>(const boost::system::error_code & a1={...}) Line 908   C++
    SmartFoxClientApi.dll!boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code>::operator()() Line 48   C++
    SmartFoxClientApi.dll!boost::asio::asio_handler_invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code> >(boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code> & function={...}, ...) Line 70   C++
    SmartFoxClientApi.dll!boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code>,boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > > >(boost::asio::detail::binder1<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > >,boost::system::error_code> & function={...}, boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > > & context={...}) Line 37   C++
    SmartFoxClientApi.dll!boost::asio::detail::wait_handler<boost::_bi::bind_t<void,boost::_mfi::mf1<void,Sfs2X::Bitswarm::UDPManager,boost::system::error_code const &>,boost::_bi::list2<boost::_bi::value<Sfs2X::Bitswarm::UDPManager *>,boost::arg<1> > > >::do_complete(boost::asio::detail::win_iocp_io_service * owner=0x04abd4c0, boost::asio::detail::win_iocp_operation * base=0x1061e8a8, const boost::system::error_code & __formal={...}, unsigned int __formal=0) Line 70   C++
    SmartFoxClientApi.dll!boost::asio::detail::win_iocp_operation::complete(boost::asio::detail::win_iocp_io_service & owner={...}, const boost::system::error_code & ec={...}, unsigned int bytes_transferred=0) Line 46   C++
    SmartFoxClientApi.dll!boost::asio::detail::win_iocp_io_service::do_one(bool block=true, boost::system::error_code & ec={...}) Line 406   C++
    SmartFoxClientApi.dll!boost::asio::detail::win_iocp_io_service::run(boost::system::error_code & ec={...}) Line 164   C++
    SmartFoxClientApi.dll!boost::asio::io_service::run() Line 59   C++
    SmartFoxClientApi.dll!Sfs2X::Bitswarm::UDPManager::StartTimer() Line 413   C++
    SmartFoxClientApi.dll!Sfs2X::Bitswarm::UDPManager::SendInitializationRequest() Line 355   C++
    SmartFoxClientApi.dll!Sfs2X::Bitswarm::UDPManager::Initialize(std::basic_string<char,std::char_traits<char>,std::allocator<char> > udpAddr={...}, unsigned short udpPort=9933) Line 94   C++
    SmartFoxClientApi.dll!Sfs2X::SmartFox::InitUDP(std::basic_string<char,std::char_traits<char>,std::allocator<char> > udpHost={...}, short udpPort=9933) Line 934   C++
>   SmartFoxClientApi.dll!Sfs2X::SmartFox::InitUDP() Line 846   C++
    SpaceWar.exe!OnLogin(unsigned __int64 context=276841744, boost::shared_ptr<Sfs2X::Core::BaseEvent> evt={...}) Line 157   C++
    SmartFoxClientApi.dll!Sfs2X::Util::DelegateOneArgument<boost::shared_ptr<Sfs2X::Core::BaseEvent> >::Invoke(boost::shared_ptr<Sfs2X::Core::BaseEvent> value={...}) Line 54   C++
    SmartFoxClientApi.dll!Sfs2X::Util::EventDispatcher::DispatchEvent(boost::shared_ptr<Sfs2X::Core::BaseEvent> evt={...}) Line 73   C++
    SmartFoxClientApi.dll!Sfs2X::SmartFox::ProcessEvents() Line 1643   C++
    SpaceWar.exe!ServerConnector::update(float deltaTime=0.0179510005) Line 59   C++
    SpaceWar.exe!BaseScene::update(float deltaTime=0.0179510005) Line 25   C++
    libcocos2d.dll!cocos2d::Scheduler::scheduleUpdate::__l2::<lambda>(float dt=0.0179510005) Line 284   C++

I did not the netcat test because the client is a Windows machine (a Visual Studio project) and getting netcat there is not straigthforward.

It also happens that if the client doesn't crash, the session is dropped in the following way;

Code: Select all

15:55:56,374 INFO  [pool-1-thread-1] stats.CCULoggerTask     - CCU stats: { Zone: SpaceWar }, CCU: 0/1
15:55:56,375 INFO  [pool-1-thread-1] stats.CCULoggerTask     - CCU stats: { Zone: --=={{{ AdminZone }}}==-- }, CCU: 0/1
15:55:56,376 INFO  [pool-1-thread-1] stats.CCULoggerTask     - CCU stats: { Zone: BasicExamples }, CCU: 0/0
15:55:56,376 INFO  [pool-1-thread-1] stats.CCULoggerTask     - CCU stats: CCU: 0/2
15:56:53,170 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 3, Type: DEFAULT, Logged: No, IP: 127.0.0.1:53996 } on Server port: 9933 <---> 53996
15:56:58,602 INFO  [SFSWorker:Ext:2] api.SFSApi     - User login: { Zone: SpaceWar }, ( User Name: sdf, Id: 2, Priv: 0, Sess: 127.0.0.1:53996 ) , Type: C++ API
15:59:06,483 INFO  [SocketReader] sessions.DefaultSessionManager     - Session removed: { Id: 3, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:53996 }
15:59:06,483 INFO  [SFSWorker:Sys:1] api.SFSApi     - User disconnected: { Zone: SpaceWar }, ( User Name: sdf, Id: 2, Priv: 0, Sess: 127.0.0.1:53996 ) , SessionLen: 127881, Type: C++ API
15:59:06,513 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 4, Type: DEFAULT, Logged: No, IP: 127.0.0.1:54023 } on Server port: 9933 <---> 54023
15:59:30,378 WARN  [SFSWorker:Sys:3] v290.SystemReqController     - com.smartfoxserver.v2.exceptions.SFSRuntimeException:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: com.smartfoxserver.v2.exceptions.SFSRuntimeException
Message: System Request rejected: { Id: 4, Type: DEFAULT, Logged: No, IP: 127.0.0.1:54023 }, Client is not logged in.
Description: Runtime error while processing request


Edit: I've downloaded a nc for windows and the message reachs the remote machine with no delay.
Thanks,
Jacobo.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Impossible to get an UDP connection

Postby Lapo » 14 Jan 2019, 15:38

This is kind of confusing.
If the client crashes --> ok, since it's dead the server detects the disconnection and that's it. However in the logs you have posted, where the client does not crash, there is no login request.

So, I am a little confused on the tests you're doing. It looks like they are not the same every time.
As far as I understand it the client is supposed to :

-> connect
-> login
-> init udp, on positive login response
-> join etc...

Can you clarify how the test works? Does it always crash on UDP init?
What OS/environment are you using for the C++ client?
Are you using the latest C++ API? (1.7.5)

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
ffelagund
Posts: 6
Joined: 19 Nov 2018, 08:09

Re: Impossible to get an UDP connection

Postby ffelagund » 14 Jan 2019, 16:03

Ok,

After some times, now I'm getting a consistent error flow.
Here is my configuration:

Server and client are on the same machine. No firewalls neither antivirus running.
Server:
Windows 10
Smartfox 2.13.4
SpaceWar extensions
Socket Addresses: 0.0.0.0:9933 TCP and 0.0.0.0:9999 UDP
bootlog:

Code: Select all

D:\sfs2eval\SpaceWar\SmartFoxServer_2X\SFS2X>sfs2x.bat
16:49:03,532 INFO  [main] v2.SmartFoxServer     - Boot sequence starts...
16:49:03,810 INFO  [main] core.SFSEventManager     - AnonymousService-1 initialized
16:49:03,824 INFO  [main] impl.DefaultFileReplicator     - Using "C:\Users\JACOBO~1.ROD\AppData\Local\Temp\vfs_cache" as temporary files store.
16:49:03,861 INFO  [main] v2.SmartFoxServer     - License loaded:

==========================================
LICENSE DETAILS
------------------------------------------
Type            : Community Edition
Max users       : 100
==========================================

16:49:03,862 INFO  [main] managers.SFSBannedUserStorage     - BanUserStorage initialized
16:49:03,869 INFO  [main] managers.SFSBannedUserManager     - BanUser data loaded: 0 records.
16:49:03,872 INFO  [main] v2.SmartFoxServer     - Protocol Type is: BINARY
16:49:03,874 INFO  [main] config.DefaultConfigLoader     - Loading: zones\BasicExamples.zone.xml
16:49:03,888 INFO  [main] config.DefaultConfigLoader     - Loading: zones\SpaceWar.zone.xml
16:49:03,899 INFO  [main] managers.SFSZoneManager     -

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 >> Zone: BasicExamples
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

16:49:03,917 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: BasicExamples }, [ Room: The Lobby, Id: 0, Group: default, isGame: false ], type = SFSRoom
16:49:03,918 INFO  [main] managers.SFSZoneManager     -

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
 >> Zone: SpaceWar
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

16:49:03,921 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: SpaceWar }, [ MMORoom: Sol, Id: 1, Group: default, AOI: (900, 750, 0) ], type = MMORoom
16:49:03,961 INFO  [main] managers.SFSRoomManager     - Room created: { Zone: --=={{{ AdminZone }}}==-- }, [ Room: AdminRoom, Id: 2, Group: default, isGame: false ], type = SFSRoom
16:49:03,984 INFO  [main] core.AdminToolService     - AdminTool Service started
16:49:04,117 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - Listening Sockets: { 0.0.0.0:9933, (Tcp) } { 0.0.0.0:9999, (Udp) }
16:49:04,117 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     -
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_|
[ 2.13.4 ]

16:49:04,118 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - SmartFoxServer 2X (2.13.4) READY!
16:49:04,674 INFO  [main] v3.SessionFilter     - BlueBox-2X Service (3.3.0) READY.
16:49:50,734 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 0:0:0:0:0:0:0:1:56003 } on Server port: 9933 <---> 56003
16:49:50,746 INFO  [SocketReader] sessions.DefaultSessionManager     - Session removed: { Id: 1, Type: DEFAULT, Logged: No, IP: 0:0:0:0:0:0:0:1:56003 }
16:49:50,751 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 0:0:0:0:0:0:0:1:56004 } on Server port: 9933 <---> 56004
16:49:50,802 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: --=={{{ AdminZone }}}==-- }, ( User Name: sfsadmin, Id: 0, Priv: 0, Sess: 0:0:0:0:0:0:0:1:56004 ) , Type: Flash ActiveX:WIN 32,0,0,114
16:49:50,805 INFO  [SFSWorker:Ext:4] api.SFSApi     - Room joined: [ Room: AdminRoom, Id: 2, Group: default, isGame: false ], { Zone: --=={{{ AdminZone }}}==-- }, ( User Name: sfsadmin, Id: 0, Priv: 0, Sess: 0:0:0:0:0:0:0:1:56004 ) , asSpect: false


Client:
Windows 10
Visual Studio 2017 (vstoolkit 140)
Client API version: 1.7.5

Connection Process:
SpaceWar login process, almost unmodified but with the following changes

Code: Select all

#define SERVER_IP "127.0.0.1"
#define SERVER_PORT 9999
void ServerConnector::connect()
{
   boost::shared_ptr<Sfs2X::Util::ConfigData> data(new Sfs2X::Util::ConfigData);
   data->Host(SERVER_IP);
   data->Port(9933);
   data->UdpHost(SERVER_IP);
   data->UdpPort(SERVER_PORT);
   data->Debug(true);
   data->Zone("SpaceWar");
   m_smartFoxServer->Connect(data);
}

void LoginScene::setAppDelegate(AppDelegate * appDelegate)
{
   BaseScene::setAppDelegate(appDelegate);

   getSmartFox()->AddEventListener(SFSEvent::LOGIN, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(OnLogin, (unsigned long long)this)));
   getSmartFox()->AddEventListener(SFSEvent::LOGIN_ERROR, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(OnLoginError, (unsigned long long)this)));
   [b]getSmartFox()->AddEventListener(SFSEvent::UDP_INIT, boost::shared_ptr<EventListenerDelegate> (new EventListenerDelegate(LoginScene::onUDPInit, (unsigned long long)this)));[/b]
}

void OnLogin(unsigned long long context, boost::shared_ptr<BaseEvent> evt) {
   LoginScene *loginScene = (LoginScene *)context;
   AppDelegate* appDelegate = loginScene->getAppDelegate();
   boost::shared_ptr<Sfs2X::SmartFox> sfs = loginScene->getSmartFox();

   CCLOG("Enable lag monitor");
   sfs->EnableLagMonitor(true, 1, 5);
   boost::shared_ptr<std::string> version = sfs->Version();
   sfs->InitUDP();
   .
   .
   .
   .
}


Those are all the changes I've made to the SpaceWar sources and in the Admin Tool.

Now, what is happening, is that when InitUPD is called, it spends a lot of minutes and finally it gets disconnected from the server (the session is lost) but the game thinks it's still connected and is sending messages to the server, that eventually fails because there is no session established between the client and the server. I don't care very much about this error, as I understand SpaceWar is just an example of how to use the API and not all error paths are controlled. What is giving me headaches is the fact that the session is lost after a lot of minutes and I can't get a working UPD connection (but a normal TCP connection works without problems)

This is the server log after the error have happened

Code: Select all

 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_|
[ 2.13.4 ]

16:59:19,863 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - SmartFoxServer 2X (2.13.4) READY!
16:59:20,354 INFO  [main] v3.SessionFilter     - BlueBox-2X Service (3.3.0) READY.
16:59:32,157 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 1, Type: DEFAULT, Logged: No, IP: 0:0:0:0:0:0:0:1:56200 } on Server port: 9933 <---> 56200
16:59:32,191 INFO  [SFSWorker:Ext:4] api.SFSApi     - User login: { Zone: --=={{{ AdminZone }}}==-- }, ( User Name: sfsadmin, Id: 0, Priv: 0, Sess: 0:0:0:0:0:0:0:1:56200 ) , Type: Flash ActiveX:WIN 32,0,0,114
16:59:32,195 INFO  [SFSWorker:Ext:4] api.SFSApi     - Room joined: [ Room: AdminRoom, Id: 2, Group: default, isGame: false ], { Zone: --=={{{ AdminZone }}}==-- }, ( User Name: sfsadmin, Id: 0, Priv: 0, Sess: 0:0:0:0:0:0:0:1:56200 ) , asSpect: false
16:59:39,972 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 2, Type: DEFAULT, Logged: No, IP: 127.0.0.1:56208 } on Server port: 9933 <---> 56208
[b]16:59:44,235 INFO  [SFSWorker:Ext:1] api.SFSApi     - User login: { Zone: SpaceWar }, ( User Name: jacobo, Id: 1, Priv: 0, Sess: 127.0.0.1:56208 ) , Type: C++ API
17:01:49,903 INFO  [SocketReader] sessions.DefaultSessionManager     - Session removed: { Id: 2, Type: DEFAULT, Logged: Yes, IP: 127.0.0.1:56208 }[/b]
17:01:49,904 INFO  [SFSWorker:Sys:1] api.SFSApi     - User disconnected: { Zone: SpaceWar }, ( User Name: jacobo, Id: 1, Priv: 0, Sess: 127.0.0.1:56208 ) , SessionLen: 125669, Type: C++ API
17:01:49,933 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 3, Type: DEFAULT, Logged: No, IP: 127.0.0.1:56236 } on Server port: 9933 <---> 56236
17:02:29,980 INFO  [Scheduler1-thread-1] sessions.DefaultSessionManager     - Session removed: { Id: 3, Type: DEFAULT, Logged: No, IP: 127.0.0.1:56236 }
[b]17:02:30,005 INFO  [SocketReader] sessions.DefaultSessionManager     - Session created: { Id: 4, Type: DEFAULT, Logged: No, IP: 127.0.0.1:56244 } on Server port: 9933 <---> 56244[/b]

As you can see, the user loses its session and gets disconnected (although later the game is receiving onConnected events, that why it is creating and removing sessions but as the user is logged out they fail. As said, this error doesn't concerns to me as this should be caused by the SpaceWar sample, after a connection error that wasn't correctly handled)

The question is, why can't I get a working UDP connection?

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

Re: Impossible to get an UDP connection

Postby Lapo » 15 Jan 2019, 11:03

Hi,
I was able to reproduce the problem locally on Mac, though Wireshark seems to show a correct UDP handshake, so I am not too sure what the problem might be at the moment. I've forwarded the issue to our C++ developer.

I'll keep you updated.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
ffelagund
Posts: 6
Joined: 19 Nov 2018, 08:09

Re: Impossible to get an UDP connection

Postby ffelagund » 15 Jan 2019, 14:19

Thank you!

Jacobo.
ffelagund
Posts: 6
Joined: 19 Nov 2018, 08:09

Re: Impossible to get an UDP connection

Postby ffelagund » 23 Jan 2019, 11:39

Hello,

Any update regarding this issue?

Thanks!
Jacobo.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Impossible to get an UDP connection

Postby Lapo » 23 Jan 2019, 11:55

Unfortunately no. Our C++ developer is out of office until the 25th.
We'll get back to you as soon as possible.
Lapo

--

gotoAndPlay()

...addicted to flash games
MBagnati
Posts: 126
Joined: 12 Feb 2013, 10:57

Re: Impossible to get an UDP connection

Postby MBagnati » 01 Feb 2019, 00:31

Hi Jacobo,
first of all let me apologize for the delay in writing this answer: unfortunately I was out of office last week.

I have investigated the issue and at the moment I have a workaround to suggest you.
It is a temporary solution that I hope will work around the error while I will look for a well-made solution

Please try these steps:
  • We want to add a new public variable as a member of the LoginScene class
    So, edit the LoginScene.h file and add this public member

    Code: Select all

          std::thread *t1;


    You will have

    class LoginScene : public BaseScene
    {
    ...
    public:
    std::thread *t1;
    ....
    };
  • We want to call InitUDP in a different thread context.
    So, edit the OnLogin method contained in the LoginScene.cpp file to replace the statement

    Sfs->InitUDP()

    with

    Code: Select all

          loginScene->t1 = new std::thread(&ServerConnector::AsyncInitUdp, ServerConnector::GetInstance());


    You will have

    void OnLogin(unsigned long long context, boost::shared_ptr<BaseEvent> evt)
    {

    // Sfs->InitUDP()
    loginScene->t1 = new std::thread(&ServerConnector::AsyncInitUdp, ServerConnector::GetInstance());

    }
  • We want to declare a new public method (AsyncInitUdp) that performs the call to InitUDP
    So, edit the ServerConnector.h file to add the declaration of a new public method

    Code: Select all

       void AsyncInitUdp();


    You will have

    class ServerConnector
    {
    ...
    public:
    void AsyncInitUdp();
    ...
    }
  • We want to implement a new public method (AsyncInitUdp) that performs the call to InitUDP
    So, edit the ServerConnector.cpp file to add the implementation of a new method

    Code: Select all

       void ServerConnector::AsyncInitUdp()
       {
               m_smartFoxServer->InitUDP();
       }

Let me know if this workaround resolves the error
Thanks
Massimo

Return to “SFS2X C++ API”

Who is online

Users browsing this forum: No registered users and 11 guests