I'm currently attempting to receive data via UDP from an extension I wrote which works with unity. It returns a few values (these are no issue atm, I get them properly without using UDP). I'm on Windows 8, using Visual Studio 2013.
Firstly I ran the SImple Chat example and it's from that I have gathered most of the knowledge about the API. From this I fashioned a simple CMD-example which calls upon an extension which returns the square of the int sent.
I now try to implement this with an extension I'm using with Unity - with Unity it works fine. I had the same errors there when I hadn't initiated UDP (by calling smartfox.initUdp()).
However, when attempting this with the c++ API nothing happens. The event i'm listening for, "SFS2X::INIT_UDP" doesn't seem to fire. I have tried calling this after connecting, after logging in and after joining a room.
What I try to do is the following:
1. Connect
2.1 Login with username
2.2 (Initiated UDP)
3. Join room
4. Sent extension request
5. Receive extension response.
What I do is to first add the eventlistener as such:
Code: Select all
// Retrieve info regarding UDP handshake
m_ptrSmartFox->AddEventListener(SFSEvent::UDP_INIT, boost::shared_ptr<EventListenerDelegate>(new EventListenerDelegate(MainFrame::OnUDPInit, (unsigned long long)this)));
I then call the InitUDP method after logging in:
Code: Select all
put("Logged in!");
put("Attempt to init UDP transmitting..");
ptrMainFrame->m_ptrSmartFox->InitUDP();
The OnUDPInit function looks like this:
Code: Select all
void MainFrame::OnUDPInit(unsigned long long ptrContext, boost::shared_ptr<BaseEvent> ptrEvent) {
// get pointer to main frame.
MainFrame* ptrMainFrame = (MainFrame*)ptrContext;
put("UDP response was received!");
boost::shared_ptr<map<string, boost::shared_ptr<void>>> ptrEventParams = ptrEvent->Params();
boost::shared_ptr<void> ptrEventParamValueSuccess = (*ptrEventParams)["success"];
if ((*((boost::static_pointer_cast<bool>)(ptrEventParamValueSuccess))) == true) {
put("UDP can be used!");
}
else {
put("UDP is not available.. Abort mission.");
}
}
The output I get from CMD is:
What's happening? Mainframe here..
SmartFoxServer connection initiated!
OnSmartFoxConnection()
Connection established!
Request for logging in sent!
Logged in!
Attempt to init UDP transmitting..
UDP handshake request sent!
..and then nothing happens. The server outputs:
15:59:24,589 INFO [SocketReader] sessions.DefaultSessionManager - Session created: { Id: 22, Type: DEFAULT, Logged: No, IP: 127.0.0.1:59853 } on Server port: 9933 <---> 59853
15:59:24,620 INFO [SFSWorker:Sys:1] api.SFSApi - User login: { Zone: BasicExamples }, ( User Name: Emomax, Id: 18, Priv: 0, Sess: 127.0.0.1:59853 ) , Type: C++ API
What I've tried and/or noticed:
- - I have made sure that UDP is available by calling "ptrSmartFox->UdpAvailable()" which returns true.
- I called "ptrSmartFox->UdpInited()" which return false. Also tried "while(!ptrSmartFox->UdpInited()) { put("UDP not inited!";)}" after calling init function which just outputs "UDP not inited!" repeatedly.
- I have tried using "InitUDP()" with both "InitUDP('localhost')" and "InitUDP('localhost', 9933)".
Is this a problem with the "InitUDP()" method or am I doing something borked?
Thankful for all help and advice. /Max