Looking for a server communication example

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

Moderators: Lapo, Bax

ganquan
Posts: 38
Joined: 17 Apr 2013, 01:42

Looking for a server communication example

Postby ganquan » 16 Jul 2015, 08:41

Hi
Is there an example to show how smartfox server talk to the other smarfox server?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Looking for a server communication example

Postby Lapo » 16 Jul 2015, 13:46

Hi,
at the moment no. If you are familiar with socket-based communication it would be pretty simple to set it up, for example using Netty which is a java library already distributed with SFS2X.
On the other hand, if you're not used to this type of programming you should probably learn the basics before venturing in these sort of lands :)

We're working on a solution that will allow to cluster multiple SFS2X in a grid-like system. At the moment we don't have a release date, yet.
Could be during next year.

Cheers
Lapo
--
gotoAndPlay()
...addicted to flash games
User avatar
Flying_Banana
Posts: 42
Joined: 04 May 2014, 07:03

Re: Looking for a server communication example

Postby Flying_Banana » 18 Jul 2015, 16:47

I am also interested in a quick way for different smart fox servers to communicate with each other. Connecting as a client is a little messy for me with all the server and client api getting mixed up and all that...
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Looking for a server communication example

Postby Lapo » 18 Jul 2015, 19:25

The simplest way is by leveraging the Netty library that is distributed with SFS2X.
Unfortunately we don't have any specific example, but it's fairly simply to startup a server/client system with it. On their website they provide a lot of examples.

You can take a look here:
http://netty.io/3.5/guide/

Otherwise, a more cluster-oriented solution could be Hazelcast but I wouldn't put it in the "quick way" category. The learning curve is a bit steep.

cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
ganquan
Posts: 38
Joined: 17 Apr 2013, 01:42

Re: Looking for a server communication example

Postby ganquan » 19 Jul 2015, 09:26

Flying_Banana wrote:I am also interested in a quick way for different smart fox servers to communicate with each other. Connecting as a client is a little messy for me with all the server and client api getting mixed up and all that...



Is connecting as a client work?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Looking for a server communication example

Postby Lapo » 20 Jul 2015, 06:26

Well yes.
There is always a client-server relationship between two endpoints.

If you want to connect two servers together one must act as server and the other as client. Typically if you want two servers to talk to each others (A and B) you will need one connection from A (client) to B (server) and another connection from B (client) to A (server).

If you want to use a system that abstracts this for you and puts all servers in communication without you worrying of the underlying details you may look into solutions such as Hazelcast, GridGain or similar. These are built for clustering and caching mainly, so depending on your use case they may or may not work for you.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games
ganquan
Posts: 38
Joined: 17 Apr 2013, 01:42

Re: Looking for a server communication example

Postby ganquan » 20 Jul 2015, 08:46

I just want to separate the lobby and games into different servers, and transfer user info between them.
I'm not familiar with socket-based communication, so if smartfox client API works on server side, that would be a quick way for me.

And, about cluster multiple SFS2X, is there a possible to release a test version at the end of this year?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Looking for a server communication example

Postby Lapo » 20 Jul 2015, 09:31

We don't have a release date for the clustered solution. It won't be out before 2016.

Best regards.
Lapo

--

gotoAndPlay()

...addicted to flash games
ganquan
Posts: 38
Joined: 17 Apr 2013, 01:42

Re: Looking for a server communication example

Postby ganquan » 21 Jul 2015, 08:56

I try to use client API in server extension, try to new SmartFox when server is ready:

Code: Select all

@Override
   public void init()
   {
      addEventHandler( SFSEventType.SERVER_READY , OnServerReadyHandler.class );
   }
   public void initSmartFoxClient( )
   {
      mSfsClient = new SmartFox( true );
      
   }


but i got an error:

Code: Select all

16:45:27,644 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - 
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|                                         
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_| 
[ 2.10.0 ]

16:45:27,644 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - SmartFoxServer 2X (2.10.0) READY!
16:45:27,657 WARN  [SFSWorker:Ext:2] core.SFSEventManager     - java.lang.NoClassDefFoundError:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NoClassDefFoundError
Message: sfs2x/client/SmartFox
Description: Error handling event: { SERVER_READY, Params: none } Listener: com.smartfoxserver.v2.entities.managers.SFSExtensionManager@406f1c5e
+--- --- ---+
Stack Trace:
+--- --- ---+
GameServer.GameServerExtension.initSmartFoxClient(GameServerExtension.java:33)
GameServer.OnServerReadyHandler.handleServerEvent(OnServerReadyHandler.java:15)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:258)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:769)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchGlobalEvent(SFSExtensionManager.java:670)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:638)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:884)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:65)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

16:45:29,940 INFO  [main] v3.SessionFilter     - BlueBox-2X Service (3.0.2) READY.


is there anything to set at server side?
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Looking for a server communication example

Postby Lapo » 21 Jul 2015, 10:03

Did you deploy the dependencies as well?
It looks like your extension is unable to load the necessary API classes. Make sure to deploy the API jars in the same folder as your Extension.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
ganquan
Posts: 38
Joined: 17 Apr 2013, 01:42

Re: Looking for a server communication example

Postby ganquan » 21 Jul 2015, 14:51

ok, thanks
votagusvotag
Posts: 38
Joined: 07 Nov 2016, 12:26

Re: Looking for a server communication example

Postby votagusvotag » 03 Mar 2017, 19:40

Lapo wrote:We're working on a solution that will allow to cluster multiple SFS2X in a grid-like system. At the moment we don't have a release date, yet.
Could be during next year.

Cheers


Are you still working on this solution? That would be a very cool feature.
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Looking for a server communication example

Postby Lapo » 04 Mar 2017, 08:38

Good question:
at the moment it's not a high priority. We have done lots of prototyping and testing, and found the idea to be feasible but there are side effects: it introduces a lot of complexity which just can't be hidden from the developer.
Whenever you have distributed state in the mix, things get very complicated very quickly, in terms of concurrency, scalability, debugging, monitoring, maintenance, etc...

We feel like the complexity of multiplayer development increases orders of magnitude and it gets "scary" pretty quickly... meaning that most developers, even with good experience, will probably get discouraged.

This is essentially why there's no such thing on the market these days, at least not one with the level of features that SFS2X offers.
(The cloud-based options have very basic features, probably 10% or less of what we provide, so they don't really compare)

We haven't dropped the idea, but for the time being we're taking a break from that project, although we may resume it in the future.

Cheers

p.s. = if you're interested in the topic you can read more here: http://smartfoxserver.com/blog/white-pa ... tegration/
Lapo

--

gotoAndPlay()

...addicted to flash games
User avatar
gabrielvpy
Posts: 69
Joined: 23 Jul 2015, 20:18

Re: Looking for a server communication example

Postby gabrielvpy » 05 Apr 2018, 18:05

ganquan wrote:I try to use client API in server extension, try to new SmartFox when server is ready:

Code: Select all

@Override
   public void init()
   {
      addEventHandler( SFSEventType.SERVER_READY , OnServerReadyHandler.class );
   }
   public void initSmartFoxClient( )
   {
      mSfsClient = new SmartFox( true );
      
   }


but i got an error:

Code: Select all

16:45:27,644 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - 
 _____ _____ _____    ___ __ __
|   __|   __|   __|  |_  |  |  |
|__   |   __|__   |  |  _|-   -|
|_____|__|  |_____|  |___|__|__|                                         
 _____ _____ _____ ____  __ __
| __  |   __|  _  |    \|  |  |
|    -|   __|     |  |  |_   _|
|__|__|_____|__|__|____/  |_| 
[ 2.10.0 ]

16:45:27,644 INFO  [SFSWorker:Sys:1] v2.SmartFoxServer     - SmartFoxServer 2X (2.10.0) READY!
16:45:27,657 WARN  [SFSWorker:Ext:2] core.SFSEventManager     - java.lang.NoClassDefFoundError:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Exception: java.lang.NoClassDefFoundError
Message: sfs2x/client/SmartFox
Description: Error handling event: { SERVER_READY, Params: none } Listener: com.smartfoxserver.v2.entities.managers.SFSExtensionManager@406f1c5e
+--- --- ---+
Stack Trace:
+--- --- ---+
GameServer.GameServerExtension.initSmartFoxClient(GameServerExtension.java:33)
GameServer.OnServerReadyHandler.handleServerEvent(OnServerReadyHandler.java:15)
com.smartfoxserver.v2.extensions.SFSExtension.handleServerEvent(SFSExtension.java:258)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:769)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchGlobalEvent(SFSExtensionManager.java:670)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.dispatchEvent(SFSExtensionManager.java:638)
com.smartfoxserver.v2.entities.managers.SFSExtensionManager.handleServerEvent(SFSExtensionManager.java:884)
com.smartfoxserver.v2.core.SFSEventManager$SFSEventRunner.run(SFSEventManager.java:65)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:722)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

16:45:29,940 INFO  [main] v3.SessionFilter     - BlueBox-2X Service (3.0.2) READY.


is there anything to set at server side?


I'm doing the exact same thing. With a very similar code. But I cant get the client to initialize. The worst part is that I don't event get an out put. What could be happening? This is my code:

Code: Select all

try {
         extension.logInfo("Server status INIT");
         SmartFox sfs = new SmartFox(true);
         extension.logInfo("Post SFS2X client");
         ConfigData cfg = new ConfigData();
         cfg.setHost(extension.getMainServerDNS());
         cfg.setPort(9933);
         cfg.setZone("ProyectoUno");
         ISFSObject data = new SFSObject();
         data.putUtfString("server", extension.getMyRegion());
         data.putInt("users_in_server", extension.getParentZone().getUserCount());
         ClienteSFS2X.talkToMainServer(cfg, "server_status", extension.getLog(), data, extension.getMyUserName(),
                    extension.getMyPassword());
      } catch (Exception e) {
         e.printStackTrace();
      } finally {
         extension.logInfo("Server status END");
      }


In the output it only prints the "Server status INIT" and "Server status END". Something happens in this line: SmartFox sfs = new SmartFox(true); because it doesn't print "Post SFS2X client".

Code: Select all

14:16:32,987 INFO  [pool-1-thread-1] zone.ZoneExtension     - Server status INIT
14:16:32,995 INFO  [pool-1-thread-1] zone.ZoneExtension     - Server status END
We made an awesome GPS - MOBA.
Try it out here: Get Fhacktions
User avatar
Lapo
Site Admin
Posts: 23009
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Looking for a server communication example

Postby Lapo » 06 Apr 2018, 07:54

I'm doing the exact same thing. With a very similar code. But I cant get the client to initialize. The worst part is that I don't event get an out put. What could be happening? This is my code:


The error on the server side says that the classes you're using are not found in the classpath.
Are you sure you've deployed the necessary dependencies?

The API comes with different jar files, you will need to pack those with your Extension as well, but actually not all of them.
This is the list of dependencies provided with the client API:

    commons-lang-2.4.jar
    jdom.jar
    netty-3.2.2.Final.jar
    sfs2x-client-core.jar
    slf4j-api-1.6.1.jar
    slf4j-simple-1.6.1.jar

The bolded ones are necessary. The other are not as they already are available in the main server's classpath.

Cheers
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: No registered users and 60 guests