Socket Error Issue

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

Moderators: Lapo, Bax

Sreelu
Posts: 7
Joined: 03 Oct 2016, 08:02

Socket Error Issue

Postby Sreelu » 03 Oct 2016, 08:11

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!!
User avatar
Lapo
Site Admin
Posts: 18607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error Issue

Postby Lapo » 03 Oct 2016, 08:35

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
Lapo
--
gotoAndPlay()
...addicted to flash games
Sreelu
Posts: 7
Joined: 03 Oct 2016, 08:02

Re: Socket Error Issue

Postby Sreelu » 03 Oct 2016, 10:07

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?
User avatar
Lapo
Site Admin
Posts: 18607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error Issue

Postby Lapo » 03 Oct 2016, 14:47

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
Lapo

--

gotoAndPlay()

...addicted to flash games
Sreelu
Posts: 7
Joined: 03 Oct 2016, 08:02

Re: Socket Error Issue

Postby Sreelu » 04 Oct 2016, 06:50

Using sfsapi of client side i.e., sfs2x.client.core.SFSEvent.. and platform is JAVA
User avatar
Lapo
Site Admin
Posts: 18607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error Issue

Postby Lapo » 04 Oct 2016, 09:13

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
Lapo

--

gotoAndPlay()

...addicted to flash games
Sreelu
Posts: 7
Joined: 03 Oct 2016, 08:02

Re: Socket Error Issue

Postby Sreelu » 18 Oct 2016, 07:20

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
User avatar
Lapo
Site Admin
Posts: 18607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error Issue

Postby Lapo » 18 Oct 2016, 10:20

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
Lapo

--

gotoAndPlay()

...addicted to flash games
Sreelu
Posts: 7
Joined: 03 Oct 2016, 08:02

Re: Socket Error Issue

Postby Sreelu » 18 Oct 2016, 10:56

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
User avatar
Lapo
Site Admin
Posts: 18607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error Issue

Postby Lapo » 18 Oct 2016, 15:36

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.
Lapo

--

gotoAndPlay()

...addicted to flash games
Sreelu
Posts: 7
Joined: 03 Oct 2016, 08:02

Re: Socket Error Issue

Postby Sreelu » 19 Oct 2016, 06:21

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!!
Sreelu
Posts: 7
Joined: 03 Oct 2016, 08:02

Re: Socket Error Issue

Postby Sreelu » 12 Jan 2017, 10:24

Late reply!!! sorry for tht..it worked tht way..Thanks!! :)
User avatar
Lapo
Site Admin
Posts: 18607
Joined: 21 Mar 2005, 09:50
Location: Italy

Re: Socket Error Issue

Postby Lapo » 12 Jan 2017, 10:45

:D
Lapo

--

gotoAndPlay()

...addicted to flash games

Return to “SFS2X Questions”

Who is online

Users browsing this forum: hoangdoanh and 7 guests