Page 1 of 1

Socket Error Issue

Posted: 03 Oct 2016, 08:11
by Sreelu
We are facing socket error/io error issues as we are trying to test some connection issues by unplugging the ethernet cable..(Iam aware that we shouldnot be testing connection events by unplugging cable.)but we have a requirement, where if users unplug the cable..it should be known at server side and handle such scenarios as how we react for CONNECTION_LOST event.

As we are unplugging the cable, USER_DISCONNECT is not being raised by SFS.Please help how to know at server end, for socket error issues!!

Re: Socket Error Issue

Posted: 03 Oct 2016, 08:35
by Lapo
Hi,
there is a reason why we recommend not to test by unplugging the ethernet cable. :)

The TCP protocol requires to exchange messages in order to end a connection. If you unplug the cable communication is no longer possible. Ergo no disconnection event.

What will happen is that eventually a TCP timeout will kick in and finally generate the disconnection event, but it may take a long time and it's difficult to predict since every OS uses different settings. (e.g. it may take 10 minutes in Windows and 50 minutes in Linux etc...)

cheers

Re: Socket Error Issue

Posted: 03 Oct 2016, 10:07
by Sreelu
Thanks lapo for the fast reply..and also i would like to know, SFSEvent.SOCKET_ERROR is not visible in SFSEvent class.Is there anything to do with sfs release versions?

Re: Socket Error Issue

Posted: 03 Oct 2016, 14:47
by Lapo
When you say the event is not visible in the SFSEvent class, what API are you referring to? Client side API? If so, which platform?

Thanks

Re: Socket Error Issue

Posted: 04 Oct 2016, 06:50
by Sreelu
Using sfsapi of client side i.e., sfs2x.client.core.SFSEvent.. and platform is JAVA

Re: Socket Error Issue

Posted: 04 Oct 2016, 09:13
by Lapo
Thanks.
Well the class SFSEvent under the sfs2x.client.core package does contain an event called SOCKET_ERROR.
It's always been there, since the first release of the Java API.

Doesn't it show up in your IDE?

cheers

Re: Socket Error Issue

Posted: 18 Oct 2016, 07:20
by Sreelu
Its not showing in my IDE!! :(

Iam trying to add it the below way:
Sfs.addEventListener(SFSEvent.SOCKET_ERROR, eventHandler);

Says...SOCKET_ERROR cannot be resolved..

Also, when we call explicitly
SmartFox Sfs = new SmartFox();
Sfs.disconnect();

Does Sfs.disconnect() method fires CONNECTION_LOST event?? Iam not getting it..or am i lookin it in wrong way?? Please let me know

Re: Socket Error Issue

Posted: 18 Oct 2016, 10:20
by Lapo
It sounds like something is wrong with the API jar files you're using. I highly recommend to download the latest Java API from here:
http://www.smartfoxserver.com/download/sfs2x#p=client

Also, when we call explicitly
SmartFox Sfs = new SmartFox();
Sfs.disconnect();

Does Sfs.disconnect() method fires CONNECTION_LOST event?? Iam not getting it..or am i lookin it in wrong way?? Please let me know

Yes when you call disconnect() you will receive the CONNECTION_LOST event, provided you were connected.
In your example code you're calling disconnect without even connecting. Doesn't make sense :)

cheers

Re: Socket Error Issue

Posted: 18 Oct 2016, 10:56
by Sreelu
I just gave 2 lines of code for giving an overview of my issue..iam actually connecting before to disconnect method..
Now Iam able to see CONNECTION_LOST event being fired..mistakenly, eventlisteners are removed before calling disconnect method..Issue@myend..sorry!!

But at some point, Iam calling disconnect method and then connect on SmartFox.

Sfs.disconnect();

and then
Sfs = new SmartFox();
Sfs.loadConfig(getCfgPath(), true);
eventHandler = new SmartFoxEventHandler();

Sfs.addEventListener(SFSEvent.CONNECTION, eventHandler);
Sfs.addEventListener(SFSEvent.CONNECTION_LOST, eventHandler);

Sfs.addEventListener(SFSEvent.LOGIN, eventHandler);
Sfs.addEventListener(SFSEvent.EXTENSION_RESPONSE, eventHandler);

When this is being executed, at first CONNECTION_LOST and then CONNECTION event are being fired..
At times, between these two events..Iam getting below 'Socket error'..,any help from ur end to solve this?


SEVERE: Connection with SFS Server Lost. Time:Tue Oct 18 16:13:20 IST 2016
1200685 [New I/O client worker #2-1] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: null
1200685 [New I/O client worker #2-1] ERROR sfs2x.client.core.sockets.TCPSocketLayer - TCPSocketLayer: Socket error: null
INFO: Connection Event:
INFO: LoginEvent: Connected with SFS. Time:Tue Oct 18 16:13:23 IST 2016

Re: Socket Error Issue

Posted: 18 Oct 2016, 15:36
by Lapo
I am not sure what the Socket error is referring to, probably the previous disconnection? If so it shouldn't be any concern, there's usually a socket error detected on every disconnection.

Also, after a disconnection you may give a second of pause before restarting a new connection.

Re: Socket Error Issue

Posted: 19 Oct 2016, 06:21
by Sreelu
Yeah..the socket error is for the previous disconnection.I will try to give a thread sleep..and then start the connection.Hope this resolves the error..Thanks alot Lapo!!

Re: Socket Error Issue

Posted: 12 Jan 2017, 10:24
by Sreelu
Late reply!!! sorry for tht..it worked tht way..Thanks!! :)

Re: Socket Error Issue

Posted: 12 Jan 2017, 10:45
by Lapo
:D