Cannot work with the server, it constantly kicks me out.

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

Moderators: Lapo, Bax

sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 31 Oct 2019, 09:57

Hi.

I'm using Java Client v.1.7.6.
The server is started on TCP/UDP 444 port locally.

I can normally connect to via TCP. I get Connect response but when I'm trying to log in with the custom login request
it just disconnects me!

I don't have any event for ExtensionResponse - but i see in logs my SFSObject I'm sending from the server.

I get normally login response from the server and have local class - a full replica of the server's one on the client side.
But after that:

5163 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling New Packet of size 699
5163 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Data: 696, previous state: 0/696
5163 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - <<< Packet Complete >>>
5166 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Data Read: Binary size: 104
80 00 65 12 00 03 00 01 70 12 00 03 00 02 62 73 ..e.....p.....bs
10 00 03 00 09 41 76 61 69 6C 61 62 6C 65 00 04 .....Available..
41 77 61 79 00 08 4F 63 63 75 70 69 65 64 00 02 Away..Occupied..
6D 76 11 00 01 11 00 03 08 00 0D 24 5F 5F 42 56 mv.........$__BV
5F 53 54 41 54 45 5F 5F 02 04 08 00 09 41 76 61 _STATE__.....Ava
69 6C 61 62 6C 65 00 02 62 6C 11 00 00 00 01 61 ilable..bl.....a
03 00 C8 00 01 63 02 00 .....c..

5166 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Data: 104, previous state: 696/696
5166 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - <<< Packet Complete >>>
5167 [Thread-3] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: com/smartfoxserver/v2/entities/User
5167 [Thread-2] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: com/smartfoxserver/v2/entities/User

and client disconnects from the server by itself.

Exacly the same code works fine on as3 and c#, but not java

Lapo, Please help!!!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot work with the server, it constantly kicks me out.

Postby Lapo » 31 Oct 2019, 13:03

Hi,
if the customLogin flag in your Zone is active you need to add a listener in your Extension that handles the SFSEvent.LOGIN event, otherwise the whole login process doesn't get triggered and you will be kicked out, because your Session timeouts without logging in.

Hope it helps
Lapo
--
gotoAndPlay()
...addicted to flash games
sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Re: Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 04 Nov 2019, 08:29

Hi, Lapo.

Thanks for the answer.

The server side is completely developed and worked well with our Unity and Flash clients, so there are no any problems on the server side.

I'm trying to connect to the server through the Java client.

I get the login response on the client side (I see it in debug logs - all the data in place) but Login Event has data = null, but correct zone name and SFS user.

There are some other logs appear in the console like:
INFO sfs2x.client.controllers.SystemController - Message: ResSetUserVariables { Message id: 12 }

but after that bang and I have :

220370 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Data: 756, previous state: 696/696
220370 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - <<< Packet Complete >>>
220371 [Thread-4] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: com/smartfoxserver/v2/entities/User
220371 [Thread-2] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: com/smartfoxserver/v2/entities/User

What is the problem with SFS User object that it hangs the whole connection? Cannot understand!!!

PS: I'm using server libraries we are using on the server side with all responses and VOs we are returning from the server. And all these responses are attached to java client as external libs (via maven).

When I put the raw classes on the Java's client side - it seems working, at least it doesn't kick me out, and I see some vars updating messages in the console.

So what is the problem, could you help?
It's not a solution to duplicate all the ready classes from the server side on the client's one.
Do you have any ideas what to provide more to find the cause? And it's a very urgent problem :(((
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot work with the server, it constantly kicks me out.

Postby Lapo » 04 Nov 2019, 09:30

Hi,
I get the login response on the client side (I see it in debug logs - all the data in place) but Login Event has data = null, but correct zone name and SFS user.

The data parameter is optional and it depends on what you send from the server side. Are you sure the data is sent from your Extension?

PS: I'm using server libraries we are using on the server side with all responses and VOs we are returning from the server. And all these responses are attached to java client as external libs (via maven).

Can you please explain exactly what other server side jars you're using? If you're loading SFS2X jar files on the client side you might be causing class collisions with the client API classes.

When I put the raw classes on the Java's client side - it seems working, at least it doesn't kick me out, and I see some vars updating messages in the console.

This is also is confusing. What raw classes are you referring to?

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Re: Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 04 Nov 2019, 11:27

Hi, Lapo.

About server side libraries:
It's only about our internal libs which have serializable DTOs - responses, VOs, etc. No SFS2x server libs are included. We don't use any SFS2x server side libs under the client.

When these libs are in sfs2x-client classpath as the external libs - it doesn't work - constantly kicks me out with the only SFS2 user error I shared above.
If I put same class with java code under the client project and removing them as jars - it works.

When it works, sometimes I have problems with serialization like:
1519 [New I/O client worker #1-1] ERROR sfs2x.client.core.SFSIOHandler - Error handling data: com.xxx.ResponseAAA cannot be cast to com.smartfoxserver.v2.entities.data.ISFSObject
java.lang.ClassCastException: com.xxx.ResponseAAA cannot be cast to com.smartfoxserver.v2.entities.data.ISFSObject
at com.smartfoxserver.v2.entities.data.SFSObject.getSFSObject(SFSObject.java:471)

when I restarts the server sometimes it goes away...

Any suggestion will be appreciated! Thanks in advance!
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot work with the server, it constantly kicks me out.

Postby Lapo » 04 Nov 2019, 16:13

Hi,
those errors suggest that there's a class conflict of some sort, maybe caused by duplicate classes. What causes this I don't know. I should know more.

When these libs are in sfs2x-client classpath as the external libs - it doesn't work - constantly kicks me out with the only SFS2 user error I shared above.
If I put same class with java code under the client project and removing them as jars - it works.

Are you sure your jar files are built correctly?
I would recommend checking the content of those jar files and making sure your IDE is not packing the project dependencies into the jar files, which it can happen.
In other words you should make sure that only your classes are included and nothing else.

Let's fix this first and then we'll investigate the other problem.
Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games
sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Re: Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 05 Nov 2019, 08:39

Hi, Lapo.

It's a production jar we are already using in the big gaming platform, so I'm 100% sure we have all the required stuff and it is working well on the server side.

I just checked again content of the jar libs we are using under the test client - they don't have any SFS2x server side libraries only from SFS2 client -
sfs2x-client-core.jar
SFS2X_API_Java.jar
json-lib-2.2.3-jdk15.jar
and 2 our libs with all the DTO we are using to send from the server as responses, VOs etc...
BaseLib-1.3.3.jar
BaseExtensionLib-1.3.2.jar

Our 2 jars don't contain any SFS2 classes (neither server's side ones nor any SFS2x server dependencies).

When these 2 jars are added to our sfs2x test client we have it now working

We are using java 8 on both server and client sides. Both are the latest versions (installed from your site just 1 week ago).


Please find below our simple test code:

Code: Select all

   SmartFox sfsClient = new SmartFox(true);

        sfsClient.addEventListener(SFSEvent.CONNECTION_LOST, e -> {
            System.out.println("connection lost!");
        });

        sfsClient.addEventListener(SFSEvent.EXTENSION_RESPONSE, e -> {
            System.out.println("extension response!!!");
        });

        ConfigData configData = new ConfigData();
        configData.setHost("127.0.0.1");
        configData.setPort(444);
        configData.setZone("aaa");
        configData.setUseBBox(false);
        configData.setDebug(true);

        sfsClient.connect(configData);

        Thread.sleep(1000);

        ISFSObject params = new SFSObject();
        params.putUtfString("version",VERSION);
        params.putInt("cv", 1);
        params.putBool("force", false);

        sfsClient.addEventListener(SFSEvent.LOGIN, e -> {
            System.out.println("login!");
        });

        sfsClient.addEventListener(SFSEvent.LOGIN_ERROR, e -> {
            System.out.println("login error!");
        });


        sfsClient.send(new LoginRequest("userA", DigestUtils.md5Hex("1"), "aaa", params));

        Thread.sleep(3000);



We receive our custom Login Response (Login event is fired), there are no errors about deserialisation problems. Client gets disconnected
Last info In debug logs :
2597 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling New Packet of size 699
2597 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Data: 696, previous state: 0/696
2597 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - <<< Packet Complete >>>
2600 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Data Read: Binary size: 104
80 00 65 12 00 03 00 01 70 12 00 03 00 02 62 73 ..e.....p.....bs
10 00 03 00 09 41 76 61 69 6C 61 62 6C 65 00 04 .....Available..
41 77 61 79 00 08 4F 63 63 75 70 69 65 64 00 02 Away..Occupied..
6D 76 11 00 01 11 00 03 08 00 0D 24 5F 5F 42 56 mv.........$__BV
5F 53 54 41 54 45 5F 5F 02 04 08 00 09 41 76 61 _STATE__.....Ava
69 6C 61 62 6C 65 00 02 62 6C 11 00 00 00 01 61 ilable..bl.....a
03 00 C8 00 01 63 02 00 .....c..

2600 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Data: 104, previous state: 696/696
2600 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - <<< Packet Complete >>>
2601 [Thread-3] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: com/smartfoxserver/v2/entities/User
2601 [Thread-2] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: com/smartfoxserver/v2/entities/User
connection lost!


Next attempt - I remove our 2 jars and just replace it with jars content - just java classes, and have the same response in debug logs.

Next attempt - I remove DTO classes under the server completely, and have errors about deserialisation problems:

2381 [New I/O client worker #1-1] ERROR sfs2x.client.core.SFSIOHandler - Error handling data: java.lang.ClassNotFoundException: com.xxx.yyy.vo.VO1
com.smartfoxserver.v2.exceptions.SFSRuntimeException: java.lang.ClassNotFoundException: com.xxx.yyy.vo.VO1

But in this case client doesn't get disconnected - so I'm still connected but no more packets from the server.

Next attempt - I put raw java code under our test client.

I get a deserialisation error here as well:
2127 [New I/O client worker #1-1] ERROR sfs2x.client.core.SFSIOHandler - Error handling data: com.xxx.yyy.ResponseA cannot be cast to com.smartfoxserver.v2.entities.data.ISFSObject
java.lang.ClassCastException: com.xxx.yyy.ResponseA cannot be cast to com.smartfoxserver.v2.entities.data.ISFSObject


then I restart the server and it works well, I see packets are coming from the server and client is still online

6314 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling New Packet of size 45
6314 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - Handling Data: 42, previous state: 0/42
6314 [New I/O client worker #1-1] INFO sfs2x.client.core.SFSIOHandler - <<< Packet Complete >>>
6314 [New I/O client worker #1-1] INFO sfs2x.client.controllers.SystemController - Message: ResUserCountChange { Message id: 1001 }
{ Dump: }

(short) sc: 22
(int) r: 200
(short) uc: 0


I'm ready to provide any kind of information you need to make this going! Just let me know what do you need from me.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot work with the server, it constantly kicks me out.

Postby Lapo » 05 Nov 2019, 08:54

Honestly I have no idea about what is going on, as I don't know what your Extension and custom classes are doing.
The example code you showed doesn't look good to me. You should send the login request inside the connection handler, only when the "success" parameter is true.
(Maybe you did that just for quick testing purpose, but it makes things more confusing and prone to errors.)

Also you showed two client debug sessions, one which is supposed to show the disconnection issue and one that shows a regular session. However they're completely different in terms of communication so I don't know what I am looking at.

This sort of issues should tackled step by step. First of all make sure that the most basic login works. Which means, send the credentials, check them on the server side and that's it. If you're sending other data during the login process, remove that temporarily so that you're testing the most simple of scenarios.
If that works, you can re-integrate the other pieces of the login process one by one and see where exactly you get the problem.

Also... is this issue being tested locally or over the internet?
Let us know.
Lapo

--

gotoAndPlay()

...addicted to flash games
sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Re: Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 05 Nov 2019, 09:07

Hi, Lapo.
Thanks for the update.

All tests are local via TCP without BB.
Okay i will create you a simple test app to show you the problem in a better way.
Thanks.
sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Re: Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 06 Nov 2019, 14:08

Hi, Lapo.

Please find the simple test in my dropbox
https://www.dropbox.com/s/l8awar9vbc78v ... m.zip?dl=0

server and client source codes are there along with zone config and target jar files

You can clearly see the problem with ISFSObject casting.

Thanks, looking forward for your replay.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot work with the server, it constantly kicks me out.

Postby Lapo » 06 Nov 2019, 16:18

Thanks, we'll take a look and get back to you.
Lapo

--

gotoAndPlay()

...addicted to flash games
sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Re: Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 14 Nov 2019, 09:42

Hi, Lapo. Any update on the problem?
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot work with the server, it constantly kicks me out.

Postby Lapo » 14 Nov 2019, 10:45

Hi,
I am sorry for the delay in responding.

The problem is in this line of your Extension's JoinZoneHandler class,

Code: Select all

send("loginResponse", SFSObject.newFromObject(new LoginResponse()), user);

Serialized objects can be passed as parameters but they need to be wrapped in an SFSObject so that you can extract them on the client side.
Here's how it works:
Server side

Code: Select all

ISFSObject response = new SFSObject()
response.put("resp", SFSObject.newFromObject(new LoginResponse()));
send(...);


Client side

Code: Select all

sfsClient.addEventListener(SFSEvent.EXTENSION_RESPONSE, e ->
{
    ISFSObject params = (ISFSObject) e.getArguments().get("params");
    LoginResponse resp = (LoginResponse) params.getClass("resp");
});


More on this in the Java client side docs:
http://docs2x.smartfoxserver.com/api-do ... N_RESPONSE

Hope it helps
Lapo

--

gotoAndPlay()

...addicted to flash games
sadensmol
Posts: 25
Joined: 20 Feb 2018, 05:25

Re: Cannot work with the server, it constantly kicks me out.

Postby sadensmol » 14 Nov 2019, 12:21

Hi, Lapo.

First I have to say to you - this technique we are using in the live project and it works fine on your C# and JS client libs and AS3 as well. The only problem - with this java's one.

I don't see any problems with the code in the example above on the server side:
according to your implementation:

Code: Select all

protected void send(String cmdName, ISFSObject params, User recipient)


so we do the right thing:

Code: Select all

send("loginResponse", SFSObject.newFromObject(new LoginResponse()), user);


we send command name , valid ISFSObject and a user.

Just checked again server side documentation and it doesn't say anything about wrapping SFSObject into SFSObject (sounds awful right?).

Once again - it works fine on all other platforms, we do everything according with your server side docs, so

Could you please ask your developers to take a look at your java client library, otherwise we will need to hack it to get it working properly (according to the docs).

Thanks.
User avatar
Lapo
Site Admin
Posts: 23008
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Cannot work with the server, it constantly kicks me out.

Postby Lapo » 14 Nov 2019, 17:08

Hi,
I've tested this under our reference API which is the Actionscript 3 API. This is the API from which everything else is derived.

When you send an Extension message from server to client you do it like this:

Code: Select all

ISFSObject message = new SFSObject();
message.putUtfString("Greet", "Ciao");
message.putInt("Year", 2019);

send("CommandName", message, ...);

This results in the following data structure being received on the client side:

Code: Select all

[SFS2X|INFO] { Message id: 13 }
{ Dump: }

   (utf_string) c: CommandName
   (sfs_object) p:
      (int) Year: 2019
      (utf_string) Greet: Ciao

The c and p keys in the main object follow the SFS2X protocol representing the Command and Parameters fields of an Extension message.

When we run your server side code the client side receives this structure instead:

Code: Select all

[SFS2X|INFO] { Message id: 13 }
{ Dump: }

   (utf_string) c: loginResponse
   (class) p: [object LoginResponse]

As you can see the p field is already pointing to the deserialized object rather than an SFSObject instance.

All you need to do is conform to the protocol, by wrapping the result of the serialization into an SFSObject.

Thanks
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Java / Android API”

Who is online

Users browsing this forum: No registered users and 21 guests