json - How to handle RPCs in client-server PlayN game? -



json - How to handle RPCs in client-server PlayN game? -

i'd utilize playn create client/server card game, e.g. hearts. while i'm focusing on html5 output, i'd ideally output-platform-agnostic in case decide create android client in future. how should approach rpc mechanism?

these options i've thought of:

use json rpcs get()/post() methods - write servlet accepts/returns json, , create versions of client code utilize that. seems doable, i'm concerned json's verbosity. 1 time hearts working i'd move on more complex games, , i'm worried json result in lot of much-larger-than-necessary messages beingness passed , forth between client , server. don't know how work json in java, assume doable. assumptions in-line? how java work json? continue using gwt-rpc. can taking asynchronous service interface in core (platform-agnostic) constructor, , in html main() pass in gwt async interface generated gwt.create(myservice.class) (or @ to the lowest degree wrapper around it). have no thought how work non-html versions though. possible me utilize gwt-rpc client-side java code directly? use other form of rpc. suggestions?

for gwt rpc on java , android platforms, i'm experimenting using gwt-syncproxy provide java client access gwt rpc methods, , i'm using guice, gin, , roboguice on respective target platforms inject appropriate asynchronous service instances instantiated game object.

in core/pom.xml playn project, include next dependency coordinates back upwards di gin/guice/roboguice needed:

<dependency> <groupid>javax.inject</groupid> <artifactid>javax.inject</artifactid> <version>1</version> </dependency>

then add together @inject annotations fields within of concrete game implementation:

public class testgame implements game { @inject testserviceasync _testservice; ... }

in html/pom.xml, include dependency coordinates gin:

<dependency> <groupid>com.google.gwt.inject</groupid> <artifactid>gin</artifactid> <version>1.5.0</version> </dependency>

and create testgameginjector , testgamemodule classes:

testgameginjector.java

@ginmodules(testgamemodule.class) public interface testgameginjector extends ginjector { testgame getgame(); }

testgamemodule.java

public class testgamemodule extends abstractginmodule { @override protected void configure() { } }

since @ moment, i'm injecting testserviceasync interface, don't need set implementation in testgamemodule.configure() method; gin manages instantiation of asyncservices me via gwt.create().

i added next testgame.gwt.xml

<inherits name='com.google.gwt.inject.inject'/>

and finally, made next changes testgamehtml.java

public class testgamehtml extends htmlgame { private final testgameginjector _injector = gwt.create(testgameginjector.class); @override public void start() { htmlplatform platform = htmlplatform.register(); platform.assetmanager().setpathprefix("test/"); playn.run(_injector.getgame()); } }

and pretty much covers html5 platform playn.

for java platform, add together next dependency coordinates java/pom.xml:

<dependency> <groupid>com.gdevelop.gwt.syncrpc</groupid> <artifactid>gwt-syncproxy</artifactid> <version>0.4-snapshot</version> </dependency> <dependency> <groupid>com.google.inject</groupid> <artifactid>guice</artifactid> <version>3.0-rc2</version> </dependency>

do note gwt-syncproxy project on google code not contain pom.xml. have mavenized version of gwt-syncproxy forked , available via git @ https://bitbucket.org/hatboyzero/gwt-syncproxy.git. should able clone it, run mvn clean bundle install local maven repository.

anyways, created testgamemodule.java java platform follows:

public class testgamemodule extends abstractmodule { @override protected void configure() { bind(testserviceasync.class).toprovider(testserviceprovider.class); } public static class testserviceprovider implements provider<testserviceasync> { public testserviceasync get() { homecoming (testserviceasync) syncproxy.newproxyinstance( testserviceasync.class, deployment.gwtwebpath(), // url webapp -- http://127.0.0.1:8888/testgame "test" ); } } }

and modified testgamejava.java follows:

public class testgamejava { public static void main(string[] args) { injector _injector = guice.createinjector(new testgamemodule()); javaplatform platform = javaplatform.register(); platform.assetmanager().setpathprefix("test/images"); playn.run(_injector.getinstance(testgame.class)); } }

i went through similar exercise android platform , roboguice -- without going tremendous detail, relevant changes/snippets follows:

pom.xml dependencies

<dependency> <groupid>com.gdevelop.gwt.syncrpc</groupid> <artifactid>gwt-syncproxy</artifactid> <version>0.4-snapshot</version> </dependency> <dependency> <groupid>org.roboguice</groupid> <artifactid>roboguice</artifactid> <version>1.1.2</version> </dependency> <dependency> <groupid>com.google.inject</groupid> <artifactid>guice</artifactid> <version>3.0-rc2</version> <classifier>no_aop</classifier> </dependency>

testgameapplication.java

public class testgameapplication extends roboapplication { @override protected void addapplicationmodules(list<module> modules) { modules.add(new testgamemodule()); } }

testgamemodule.java

public class testgamemodule extends abstractmodule { @override protected void configure() { bind(testserviceasync.class).toprovider(testserviceprovider.class); } public static class testserviceprovider implements provider<testserviceasync> { public testserviceasync get() { homecoming (testserviceasync) syncproxy.newproxyinstance( testserviceasync.class, deployment.gwtwebpath(), // url webapp -- http://127.0.0.1:8888/testgame "test" ); } } }

testgameactivity.java

public class testgameactivity extends gameactivity { @override public void oncreate(bundle savedinstancestate) { final injector injector = ((roboapplication) getapplication()).getinjector(); injector.injectmembers(this); super.oncreate(savedinstancestate); } @override public void main(){ platform().assetmanager().setpathprefix("test/images"); final injector injector = ((roboapplication) getapplication()).getinjector(); playn.run(injector.getinstance(testgame.class)); } }

that's quick , dirty rundown of how got gin/guice/roboguice + gwt working in project, , have verified works on both java , html platforms beautifully.

anyways, there's gwt approach providing rpc calls multiple playn platforms :).

json client-server rpc gwt-rpc playn

Comments

Popular posts from this blog

delphi - blogger via idHTTP : error 400 bad request -

c++ - compiler errors when initializing EXPECT_CALL with function which has program_options::variables_map as parameter -

How do I check if an insert was successful with MySQLdb in Python? -