Problem in connection with sfs2x server

Post here your questions about SFS2X. Here we discuss all server-side matters. For client API questions see the dedicated forums.

Moderators: Lapo, Bax

shravan.yadav
Posts: 15
Joined: 18 Jun 2012, 07:56

Problem in connection with sfs2x server

Postby shravan.yadav » 20 Jun 2012, 07:03

Hi All,

I am trying to make a connection with sfs2x in android application.I also install the sfs2x server in my achine and start the sfs2x . I am writing this code for the same
Please solve my problem.I add all the permission in my manifest file regardbing internet.No anyexception is come but connection is not beaing stablish.In logcat TCPSocketLayer error is showing .......Please help me.

ackage com.nextgen;
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 android.app.Activity;
import android.os.Bundle;
import android.util.Log;

public class HelloAndroidActivity extends Activity implements IEventListener {
/** Called when the activity is first created. */

SmartFox sfsClient;

public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
try{
sfsClient = new SmartFox(true);
sfsClient.connect("127.0.0.1",9933);
boolean b;
b=sfsClient.isConnected();
Log.v("Is Connected ", " "+b);

}
catch(Exception e){

Log.v("Shravan Tag", e.toString());
Log.v("shravan Tag:getStackTrace()", ""+e.getStackTrace());
Log.v("shravan Tag:getCause()", e.getCause().toString());
Log.v("shravan tag:getLocalizedMessage()", e.getLocalizedMessage().toString());
Log.v("Shravan Tag:getMessage(", e.getMessage());
}
}

private void initSmartFox()
{
// Instantiate SmartFox client
Log.v("Shravan Tag2", "this is tag2");

sfsClient.addEventListener(SFSEvent.CONNECTION, this);
sfsClient.addEventListener(SFSEvent.CONNECTION_LOST, this);
sfsClient.addEventListener(SFSEvent.LOGIN, this);
sfsClient.addEventListener(SFSEvent.ROOM_JOIN, this);
sfsClient.addEventListener(SFSEvent.HANDSHAKE, this);


}

public void dispatch(BaseEvent arg0) throws SFSException {
// TODO Auto-generated method stub

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

Re: Problem in connection with sfs2x server

Postby Lapo » 20 Jun 2012, 07:49

I don't think I understand your code. First you start the connection but you don't set any listeners for the connection event.
The initSmartFox() method is never called?

We provide Android examples with source code here:
http://www.smartfoxserver.com/download/sfs2x#p=examples

In particular check the Connector Tutorial:
http://docs2x.smartfoxserver.com/Exampl ... /connector
Lapo
--
gotoAndPlay()
...addicted to flash games
shravan.yadav
Posts: 15
Joined: 18 Jun 2012, 07:56

Re: Problem in connection with sfs2x server

Postby shravan.yadav » 20 Jun 2012, 08:05

Hi,

I trying the same example but getting problem.
It is necessory to start the sfs2x when run the application?
what should be ip address and port for that ? can i connect through localhost and 8080 or127.0.0.1 and 9933 ?

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

Re: Problem in connection with sfs2x server

Postby Lapo » 20 Jun 2012, 11:01

It is necessory to start the sfs2x when run the application?

Yes, I really think so! :D
Lapo

--

gotoAndPlay()

...addicted to flash games
shravan.yadav
Posts: 15
Joined: 18 Jun 2012, 07:56

Re: Problem in connection with sfs2x server

Postby shravan.yadav » 21 Jun 2012, 05:03

hi,

What about that ?

what should be ip address and port for that ? can i connect through localhost and 8080 or127.0.0.1 and 9933 ? or any other ?
User avatar
Lapo
Site Admin
Posts: 21639
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Problem in connection with sfs2x server

Postby Lapo » 21 Jun 2012, 07:02

127.0.0.1 (localhost) works only on the local machine. If you want to reach the server from another computer in the LAN you will need to use the real network address.
To do so start the AdminTool and choose the Server Configurator.
http://docs2x.smartfoxserver.com/Gettin ... nfigurator
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 21 guests