When I try connect to wrong IP, the event which i received is CONNECTION:
11388 [Thread-5] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: connection timed out
connection
11400 [Thread-5] WARN sfs2x.client.SmartFox - You are not connected. Request cannot be sent: sfs2x.client.requests.LoginRequest@19b4ac28
Why don't CONNECTION_LOST event dispatch ?
SFSJava API (1.2.0): connect to wrong IP
Re: SFSJava API (1.2.0): connect to wrong IP
CONNECTION_LOST fires only when a connection already exists and it is dropped.
If you connect to a "wrong" IP you will still get a CONNECTION event with the success property set to false.
This is straight from the javadoc:
Take a look at the SFSEvent class here:
http://docs2x.smartfoxserver.com/api-do ... oc/client/
thanks
If you connect to a "wrong" IP you will still get a CONNECTION event with the success property set to false.
This is straight from the javadoc:
Code: Select all
package sfsTest;
import com.smartfoxserver.v2.exceptions.SFSException;
import sfs2x.client.SmartFox;
import sfs2x.client.core.BaseEvent;
import sfs2x.client.core.IEventListener;
import sfs2x.client.core.SFSEvent;
import java.util.Map;
public class MyTest
{
private SmartFox sfs;
public MyTest()
{
// Create a SmartFox instance
sfs = new SmartFox();
// Add event handler for connection
sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener()
{
public void dispatch(BaseEvent evt) throws SFSException {
// Retrieve event parameters
Map params = evt.getArguments();
if ((Boolean)params.get("success"))
System.out.println("Connection established");
else
System.out.println("Connection failed");
}
});
// Connect to server
sfs.connect("127.0.0.1", 9933);
}
}
Take a look at the SFSEvent class here:
http://docs2x.smartfoxserver.com/api-do ... oc/client/
thanks
Re: SFSJava API (1.2.0): connect to wrong IP
Ok, thanks. But i still have a problem. When i disconnect the Internet connection on pc, HTML5 client fire to the CONNECTION_LOST, but i do the same on Android or JavaSE Client, I recieve nothing. What can I do to handle that scenario ?
Re: SFSJava API (1.2.0): connect to wrong IP
If disconnect the internet connection you will get unpredictable results. It's not SFS API's fault, it depends on the inner workings of the TCP IP of each computer/device.
Often times unplugging the wifi/ethernet will not fire an event for a long time, until the TCP timeout fires.
Normally this happens more on computers and much less on mobile devices. Sounds strange that it's the other way around for you.
Thanks
Often times unplugging the wifi/ethernet will not fire an event for a long time, until the TCP timeout fires.
Normally this happens more on computers and much less on mobile devices. Sounds strange that it's the other way around for you.
Thanks
Return to “SFS2X Java / Android API”
Who is online
Users browsing this forum: No registered users and 49 guests