Java client API

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

Moderators: Lapo, Bax

isahn
Posts: 1
Joined: 29 Jan 2011, 18:53

Java client API

Post by isahn »

Hi,

do you plan to release java client API (Android compatible) for X2, and if yes when?

Thanks

Isahn
mka
Posts: 15
Joined: 31 Jan 2011, 02:43

Post by mka »

I am also anxiously waiting for the Java Client API. We need it for unit testing extensions without having to go through the game flash client. And we don't have the resources to build flash test clients to do that.

Can you at least give us an indication of when this will be released?

I don't care about an Android API. Just plain Java like there was for SFS1.6.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

We should be ready in a couple of weeks.
Lapo
--
gotoAndPlay()
...addicted to flash games
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

@mka - you can meanwhile use the Unity / C# API for unit testing if thats your goal. Works perfectly fine standalone for exactly that purpose without a requirement for Unity itself.
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Yep, and if you work with a non-Windows OS I'd recommend Mono and MonoDevelop: http://monodevelop.com/
Lapo
--
gotoAndPlay()
...addicted to flash games
adenault
Posts: 42
Joined: 07 Feb 2011, 14:22

Post by adenault »

Any updates?
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

Here's a preview version:

DOWNLOAD BETA 1

NOTES:
Currently doesn't support UDP
No Javadoc available yet, however uses same interface as the other languages so you can rely on AS3 docs or C# docs and the IDE autocomplete

Provided is a simple example exported as Eclipse project (zipped)
If you don't use Eclipse just unzip the src folders and the dependencies.


EDIT: we just released beta 2 version. Please check this post.
Lapo
--
gotoAndPlay()
...addicted to flash games
cslwkah
Posts: 13
Joined: 21 Feb 2011, 10:40

Post by cslwkah »

Thanks for your effort.

Anyone test this beta release?

It is a java version file but my project is written in android. So I convert it to a simple android test project and found 2 error.

1. Compile error happened when I first compile the code in eclipse as an new android project. The log4j jar cause heap size error. Well, I remember that android does not support log4j.

2. I remove the log4j jar and see what happen then. This time the project can be compiled but I get an runtime error. I get the verify error for the class log4j and then SmartFox. Maybe the first exception on log4j cause the second error, I guess.

So anyone have a try? I really wanta have a try on SFS2
User avatar
Lapo
Site Admin
Posts: 23438
Joined: 21 Mar 2005, 09:50
Location: Italy

Post by Lapo »

We use the slf4j API for logging so you should be able to switch logging API without too many problems.
You can go here:

download the libs and replace the log4j interface with the JDK logging ones.
I think... :)
We'll also check it out.
http://www.slf4j.org/
Lapo
--
gotoAndPlay()
...addicted to flash games
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

Not tested on Android - just standard java.

Any feedback otherwise is welcome and shoot away with questions!

/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 lapo and ThomasLund

After several try, I still can not run my android project.

I remove slf4j-api-1.5.10.jar and slf4j-log4j12.jar. Then download and add slf4j-android-1.6.1-RC1.jar into project. Here is my log. Actually the error is exactly the same as using the original slf4j*.jar files...

Code: Select all

02-22 19:44:46.390: ERROR/dalvikvm(18416): Could not find method org.apache.log4j.Logger.getRootLogger, referenced from method sfs2x.client.SmartFox.<init>
02-22 19:44:46.390: WARN/dalvikvm(18416): VFY: unable to resolve static method 1373: Lorg/apache/log4j/Logger;.getRootLogger ()Lorg/apache/log4j/Logger;
02-22 19:44:46.390: WARN/dalvikvm(18416): VFY:  rejecting opcode 0x71 at 0x0025
02-22 19:44:46.390: WARN/dalvikvm(18416): VFY:  rejected Lsfs2x/client/SmartFox;.<init> (Z)V
02-22 19:44:46.390: WARN/dalvikvm(18416): Verifier rejected class Lsfs2x/client/SmartFox;
02-22 19:44:46.390: WARN/dalvikvm(18416): threadid=3: thread exiting with uncaught exception (group=0x4000ff28)
02-22 19:44:46.390: ERROR/AndroidRuntime(18416): Uncaught handler: thread main exiting due to uncaught exception
02-22 19:44:46.400: INFO/CheckinService(97): Checkin triggered: Intent { action=android.server.checkin.CHECKIN (has extras) }, market only = true
02-22 19:44:46.400: INFO/ActivityManager(97): Stopping service: com.android.vending/.PackageMonitorReceiver$UpdateCheckinDatabaseService
02-22 19:44:46.410: ERROR/AndroidRuntime(18416): java.lang.VerifyError: sfs2x.client.SmartFox
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at com.smartcube.android.multiplayer.BasicClientExample.initSmartFox(BasicClientExample.java:38)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at com.smartcube.android.multiplayer.BasicClientExample.onCreate(BasicClientExample.java:20)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1123)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2274)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2327)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.app.ActivityThread.access$2000(ActivityThread.java:115)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1735)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.os.Handler.dispatchMessage(Handler.java:99)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.os.Looper.loop(Looper.java:123)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at android.app.ActivityThread.main(ActivityThread.java:3999)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at java.lang.reflect.Method.invokeNative(Native Method)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at java.lang.reflect.Method.invoke(Method.java:521)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:782)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:540)
02-22 19:44:46.410: ERROR/AndroidRuntime(18416):     at dalvik.system.NativeStart.main(Native Method)
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Post by ThomasLund »

Right - I got a hardcoded reference to log4j in there.

02-22 19:44:46.390: ERROR/dalvikvm(18416): Could not find method org.apache.log4j.Logger.getRootLogger, referenced from method sfs2x.client.SmartFox.<init>
02-22 19:44:46.390: WARN/dalvikvm(18416): VFY: unable to resolve static method 1373: Lorg/apache/log4j/Logger;.getRootLogger ()Lorg/apache/log4j/Logger;

Exactly that one.

I'll try to see if I can fix that one up without referencing log4j directly.

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
adenault
Posts: 42
Joined: 07 Feb 2011, 14:22

Post by adenault »

I'm using it in a pure Java project with no problem.

Cheers,

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

Post by ThomasLund »

Super Alex - thanks

The Android fix will require some changes to the API code. Will try to get to it today or tomorrow. No biggie - just am 3 days from releasing a 1 year in development game. So slightly stressed :-D

/T
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
mka
Posts: 15
Joined: 31 Jan 2011, 02:43

Post by mka »

Hi all!

Firstly thanks to Lapo for giving us the beta API. It's been a tremendous help so far.

I am using it in pure Java to test our custom extensions and event handlers. There are two things I have noticed so far:

1) The custom login does not work with the password check using the SFSApi like this:

Code: Select all

getApi().checkSecurePassword(session, clearTextPwd, sfsClientPwd)
The reason seems to be a different encryption mechanismn on both the java client and smartfox.
I worked around it by extending the provided client LoginRequest and overwriting the execute method like this:

Code: Select all

   @Override
   public void execute(SmartFox sfs)
   {
      super.execute(sfs);
      // overwrite the password with a case-insensitive version
      String pwd = sfso.getUtfString("pw");
      sfso.putUtfString("pw", pwd.toLowerCase());
   }
2) When adding SFSObject's to a UserVariable I have to explicitly set the variable type. Otherwise I get "Unsupport SFS Variable type".
So I have to do:

Code: Select all

ISFSObject obj= new SFSObject();
UserVariable var = new SFSUserVariable("varName", obj, 5);
instead of just:

Code: Select all

ISFSObject obj= new SFSObject();
UserVariable var = new SFSUserVariable("varName", obj);
Post Reply