SFSJava API (1.2.0): connect to wrong IP

Post here your questions about the Java client / Android API for SFS2X

Moderators: Lapo, Bax

hhd90
Posts: 67
Joined: 21 Dec 2012, 05:17

SFSJava API (1.2.0): connect to wrong IP

Postby hhd90 » 18 Oct 2013, 03:59

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 ?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSJava API (1.2.0): connect to wrong IP

Postby Lapo » 18 Oct 2013, 08:02

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:

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
Lapo
--
gotoAndPlay()
...addicted to flash games
hhd90
Posts: 67
Joined: 21 Dec 2012, 05:17

Re: SFSJava API (1.2.0): connect to wrong IP

Postby hhd90 » 18 Oct 2013, 13:02

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 ?
User avatar
Lapo
Site Admin
Posts: 23027
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: SFSJava API (1.2.0): connect to wrong IP

Postby Lapo » 18 Oct 2013, 13:38

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
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 49 guests