Java client API

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

Moderators: Lapo, Bax

cslwkah
Posts: 13
Joined: 21 Feb 2011, 10:40

Post by cslwkah »

thanks ThomasLund, I would wait for your release.

PS: I also test the code in pure java this morning and it seems no problem. Nice work. :lol:
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

OK - replaced log4j/sl4j with the JDK logger, fixed the password upper case hash and the SFSUserVariable issue (dumb error).

Thanks for reporting.

Need Marco to fix/recompile a jar file for me before releasing. So give it a day more and you can try again

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
esin
Posts: 6
Joined: 25 Feb 2011, 08:40

Post by esin »

hi all!

i downloaded Java client API, tried to use it in Java2SE application. but i cannot connect to server. after calling "sfs.connect" method in console i can see, that server sends me a crossdomain.xml file. then nothing happening for 20 seconds, after this i receive onConnectionLost event.

i tried to run SimpleChat example, but it cannot connect to server too. in console i see the same picture: i get crossdomain.xml file, and after 20 seconds "Connection lost" window appears.

during these 20 seconds in admin tool shown, that number of CCU is 2 (admin and application). and in server logs for each connection attempt appear two lines:

24 Feb 2011 16:42:17,865 INFO [SocketReader] bitswarm.core.SocketAcceptor - Session created: { Id: 6, Type: DEFAULT, Logged: No, IP: 127.0.0.1:57407 } on Server port: 9933 <---> 57407

24 Feb 2011 16:42:39,553 INFO [Scheduler1-thread-1] bitswarm.sessions.DefaultSessionManager - Session removed: { Id: 6, Type: DEFAULT, Logged: No, IP: 127.0.0.1:57407 }

i have never worked with your server before, so i don't know, what i did wrong. could you help me? thank you

P.s. sorry for my English
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

esin, are you listening to the connection event in your code?
Paolo Bax
The SmartFoxServer Team
esin
Posts: 6
Joined: 25 Feb 2011, 08:40

Post by esin »

hi, bax! thank you for reply

of course i do :)

Code: Select all

...
else if(event.getName().equals(SFSEvent.onConnection))
        {
        	
        	log("onconnection");
            if(event.getParams().getBool("success"))
            {
                log("connected");
            }
            else
            {
                log("not connected");
                System.exit(-2);
            }
        }
        else if(event.getName().equals(SFSEvent.onConnectionLost))
        {
        	log("connection lost");
        	System.exit(-1);
        }
...

private void log(String str)
	{
		System.out.println(str);
	}
but none of messages "connected" or "not connected" or even "onconnection" appears in console
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

Hard to know exactly what goes wrong without more info.

Do you have some info from the client log output? It should in Level.ALL mode show even the network packets.

Here is also a confirmed working unit test case - if that doesnt work, then you got some local configuration issue of some sort. Firewall, server config or similar.

Code: Select all

package test.junit;

import com.smartfoxserver.v2.exceptions.SFSException;
import org.junit.Assert;
import org.junit.Test;
import sfs2x.client.SmartFox;
import sfs2x.client.core.BaseEvent;
import sfs2x.client.core.IEventListener;
import sfs2x.client.core.SFSEvent;
import sfs2x.client.requests.LoginRequest;
import sfs2x.client.requests.LogoutRequest;

/**
 * Developer: Thomas Hentschel Lund
 * Creation timestamp: 10/02/11 20.15
 */
public class LoginRequestTest {
	private SmartFox sfs;
	private boolean loggedIn = false;

	@Test
	public void TestLoginLogout() {
		sfs = new SmartFox(true);
		sfs.addEventListener(SFSEvent.CONNECTION, new IEventListener() {
			public void dispatch(BaseEvent evt) {
				onConnection(evt);
			}
		});
		sfs.addEventListener(SFSEvent.CONFIG_LOAD_FAILURE, new IEventListener() {
			public void dispatch(BaseEvent evt) {
				onConfigLoadFailure(evt);
			}
		});

		sfs.addEventListener(SFSEvent.LOGIN, new IEventListener() {
			@Override
			public void dispatch(BaseEvent evt) throws SFSException {
				onLogin(evt);
			}
		});
		sfs.addEventListener(SFSEvent.LOGIN_ERROR, new IEventListener() {
			@Override
			public void dispatch(BaseEvent evt) throws SFSException {
				onLoginError(evt);
			}
		});
		sfs.addEventListener(SFSEvent.LOGOUT, new IEventListener() {
			@Override
			public void dispatch(BaseEvent evt) throws SFSException {
				onLogout(evt);
			}
		});

		String cfgPath = getCfgPath();

		System.out.println("Loading config from " + cfgPath);

		loggedIn = false;
		sfs.loadConfig(cfgPath, true);
		// Auto connects

		try {
			Thread.sleep(2000);

			Assert.assertEquals(true, loggedIn);
			// If we successfully also logged out then this is false
			Assert.assertTrue(sfs.isConnected());
		}
		catch (InterruptedException e) {
			Assert.assertTrue(false);
		}
	}

	private String getCfgPath() {
		return System.getProperty("user.dir") + "/config/sfs-config.xml";
	}

	private void onConnection(BaseEvent evt) {
		if ((Boolean) evt.getArguments().get("success")) {
			sfs.send(new LoginRequest("", "", sfs.getCurrentZone()));
		}
	}

	private void onLogin(BaseEvent evt) {
		loggedIn = true;
		sfs.send(new LogoutRequest());
	}

	private void onLoginError(BaseEvent evt) {
		Assert.assertTrue(false);
	}

	private void onLogout(BaseEvent evt) {
	}

	private void onConfigLoadFailure(BaseEvent evt) {
		Assert.assertTrue(false);
	}

}
the config file that is uses is:

Code: Select all

<SmartFoxConfig>
	<!-- Mandatory Settings -->
	<ip>127.0.0.1</ip>
    <udpIp>127.0.0.1</udpIp>
	<port>9933</port>
    <udpPort>9933</udpPort>
	<zone>SimpleChat</zone>
	<!-- End Mandatory Settings -->
	
	<debug>true</debug>
	
	<!-- For generic http port communication -->
	<httpPort>8080</httpPort>
	
	<!-- 
		BlueBox settings 
		
		useBlueBox: falls back to BlueBox if socket connection fails, default = true
		blueBoxPollingRate: the polling interval between requests, default 700ms
	-->
	<useBlueBox>true</useBlueBox>
	<blueBoxPollingRate></blueBoxPollingRate>
	
</SmartFoxConfig>
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
cslwkah
Posts: 13
Joined: 21 Feb 2011, 10:40

Post by cslwkah »

any update of the android api?
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

cslwkah - getting to that _now_

Small communication mistake during the week made me remove too much of the logging. So have to revert and fix again.

Sorry for the wait

/T
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

And fix is in SVN - crossing fingers that it works on the device. Any ways for me to easily test it? Is there an Android simulator that could be used without having to deploy to a device?

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
cslwkah
Posts: 13
Joined: 21 Feb 2011, 10:40

Post by cslwkah »

thanks for your effort.

Em...a bit complex, I think. You need to install the android sdk, create a new Android Virtual Devices(AVD), create a test app using the api and deploy it to your AVD.

Download the sdk:
http://developer.android.com/sdk/index.html
Guide to create the avd and deploy project:
http://developer.android.com/guide/deve ... lator.html
Development guide:
http://developer.android.com/guide/index.html

I make my first android project using over 3 hours... Or you may just post the updated version here. We may test it for you. :D
cslwkah
Posts: 13
Joined: 21 Feb 2011, 10:40

Post by cslwkah »

what's the status now?
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

as far as I know, a new build is being packed today or tomorrow. Its not me doing that, so cant promise anything on behalf of others
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Post by Bax »

We just released beta 2 version. Please check this post.
Paolo Bax
The SmartFoxServer Team
mka
Posts: 15
Joined: 31 Jan 2011, 02:43

Post by mka »

Thanks guys!

Just switched over to the new version, removed my workarounds and all is working fine.

One tiny suggestion/request though:
The AS3 API has a method that allows to retrieve all user variables from the user as array.
SFSUser.getVariables():Array

In the Java client API I can only retrieve a variable by its name or check, if it exists.
We have one single use case where we want to dump all user variables in the test client. The easiest way is to have access to all user variables similar to what's possible in the AS3 API without having to retrieve them one by one by name.

I am currently bypassing that by getting access to the "variables" property on the user via reflection.
But unless you have reasons for not allowing access to all variables at once, it would be a nice-to-have to have a getVariables() method in the Java API as well.

cheers,
Martina
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

Pure oversight - just added to SVN, so will be part of next beta!

If you run into any more of these, dont hold back posting!!

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Post Reply