Page 1 of 1

Connect server extension as client to another server

Posted: 13 Mar 2017, 03:39
by ArturAG
Hello. I want to have two different SmartFox servers communicating with each other.

Here's a diagram
[Master server] <--> [Slave server] <--> [Slave clients]

The way I thought about doing it was to have the [Slave server] act as a Client and connect itself to the [Master server]. I imagine this is possible if I include the SFS Java Client API in my Java extension for [Slave server] and start a connection from there. Maybe it's not super clean, but it should work. Right?

Alternatively, is there any way to start a client connection from the SFS Server API, without having to include the Client API?

Also, is there any reason why I shouldn't do this, or maybe take a different approach? I'll be exchanging entity positions between the two servers, which is why I didn't want to use HTTP or something between the two servers. I'm also not looking forward to use TCP/UDP/lower level stuff, because having SFSObjects eases the communication implementation quite a lot.

Re: Connect server extension as client to another server

Posted: 13 Mar 2017, 09:33
by Lapo
Hi,
ArturAG wrote:Hello. I want to have two different SmartFox servers communicating with each other.

Here's a diagram
[Master server] <--> [Slave server] <--> [Slave clients]

The way I thought about doing it was to have the [Slave server] act as a Client and connect itself to the [Master server]. I imagine this is possible if I include the SFS Java Client API in my Java extension for [Slave server] and start a connection from there. Maybe it's not super clean, but it should work. Right?

Yes, but you will have to be careful about what dependencies coming with the client side API.
The API require commons-lang, slf4j, sfs2x-core jars, but these already exist in SFS2X, so you should not deploy them. Other than that it should work.

Alternatively, is there any way to start a client connection from the SFS Server API, without having to include the Client API?

As a "coordination" tool you could use Hazelcast, which has interesting advantages. We have a white-paper here:
http://docs2x.smartfoxserver.com/Overview/white-papers
(scroll down to the bottom, it's the second last)

Cheers

Re: Connect server extension as client to another server

Posted: 18 Apr 2017, 02:51
by ArturAG
Thank you for your reply!

I tried including a SmartFox client in the Slave Server, and it works! These are the dependencies I put inside the __lib__ folder for the Java client:

Code: Select all

jdom.jar
SFS2X_API_Java.jar

However, there is an odd issue when connecting to the Master Server. After calling the SmartFox.connect() method, I have to wait for 10 seconds until the connection is started. I tested this both with a localhost server and a different machine in the same local network. After 10 seconds, these two lines are printed:

Code: Select all

Apr 18, 2017 2:37:47 AM org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool
WARNING: Failed to get all worker threads ready within 10 second(s). Make sure to specify the executor which has more threads than the requested workerCount. If unsure, use Executors.newCachedThreadPool().

After this, the connection is established, and everything works correctly. But until this point, I always have to wait 10 seconds...

I pinpointed the problem to the Netty version I have deployed. SmartFoxServer Win x64 comes with netty-3.9.0.Final.jar, but the Java API 1.7.0 client comes with the older netty-3.2.2.Final.jar. If I delete the 3.9.0 from the Slave Server and replace it with 3.2.2, then the 10 second delay disappears, and the SmartFox client inside the Slave Server connects right away. But I'm not sure what are the consequences of downgrading Netty like this.

I also tried using the Java Client by itself, outside the server, with Netty 3.9.0, and the 10 second delay happens too.

What should I do? I guess this means the Java client is not compatible with Netty 3.9.0, but I cannot have both 3.9.0 and 3.2.2 in the same Java enviromnent, can I? Even if I put netty 3.2.2 in the extensions/__lib__ folder, the server waits the 10 seconds, so it seems to be using 3.9.0.
Thank you for your attention.

Re: Connect server extension as client to another server

Posted: 18 Apr 2017, 08:25
by Lapo
Have you tried putting the client API jars in your own Extension's folder instead? That might do the trick...

Re: Connect server extension as client to another server

Posted: 19 Apr 2017, 05:55
by ArturAG
I tried it just now, but unfortunately it didn't work... :(

If it matters, I'm connecting the client inside an ISFSEventListener associated with the SERVER_READY event. I imagine this would already run inside the extension's own classloader, right?

Re: Connect server extension as client to another server

Posted: 19 Apr 2017, 09:05
by Lapo
There might be a conflict with different Netty libs, as you suggested. We'll have to investigate.

Re: Connect server extension as client to another server

Posted: 11 May 2017, 08:11
by ArturAG
The issue seems to be fixed on SmartFoxServer 2.13.0 (because 2.13 does not have any Netty in its lib folder).
Thank you! :D

Re: Connect server extension as client to another server

Posted: 11 May 2017, 09:03
by Lapo
Yes, indeed Netty has been dropped :)