No error on a failed connection?

Post here your questions about the Flash / Flex / Air API for SFS2X

Moderators: Lapo, Bax

Devon
Posts: 41
Joined: 12 Apr 2011, 16:18

No error on a failed connection?

Postby Devon » 12 Apr 2011, 16:27

I'm trying to figure out why this script won't produce an error when the connection attempt should fail...

Basically, I have intentionally entered the wrong IP and have the following code:

Code: Select all

private function onConnection(evt:SFSEvent):void
{
   if (evt.params.success)
   {
      strCurrentStep += "\nConnection successful!";
   }
   else
   {
      strCurrentStep += "\nUnable to connect to " + _conn.currentIp + ":" + _conn.currentPort;
   }
}


Instead of displaying the error, it does nothing. As if that function is not being called. However, when I enter the correct IP/Port - the "Connection successful!" message does appear as it should.

Is it constantly retrying to connect? Is there not a timeout limit? What am I doing wrong?

Thanks
User avatar
rjgtav
Posts: 2813
Joined: 19 Apr 2009, 11:31
Location: Lisbon, Portugal

Postby rjgtav » 12 Apr 2011, 17:25

well, usually it takes some time until it quits and says that it cant connect. Not sure if this is what are u asking
Skills: SFS Pro, SFS2X, AS2.0/AS3.0, Java, HTML5/CSS3/JS, C#
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Devon
Posts: 41
Joined: 12 Apr 2011, 16:18

Postby Devon » 12 Apr 2011, 17:26

Well, I kept the window open for several minutes and never received an error. :-/

Is there a way to set a timeout?
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Postby Democre » 12 Apr 2011, 19:05

You can only receive a CONNECTION event if it actually connects at the socket level. If there is some reason that it fails to fully connect after the socket connection is established, then you would receive the CONNECTION event with a false "success" parameter.

However, if the socket connection is never made, you will eventually get a socket timeout, and that won't come through the CONNECTION event. It could fail silently.

I usually put the connect method in a loop of some sorts with appropriate delay between calls. This loop exits either on successful connection, or my timeout has been reached. (while not connected AND current time is less than timeout time)

Feature request
Maybe this could be written into the client library. something like smartfox.connect(timeout). If it did timeout maybe it could fire the CONNECTION event with a false success.
Devon
Posts: 41
Joined: 12 Apr 2011, 16:18

Postby Devon » 12 Apr 2011, 19:24

Yea, I was thinking I'd just create a global bool "connected" and do a setTimeout to call a function after x seconds. If the connection is made, I'd set "connected" to true. Otherwise, when the timeout expires and calls the function it would check the bool and if still false (not connected) then it'd display an error.

My question is this, does disconnect() also cancel any current connection attempts or does it only close successful connections?
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Postby Democre » 12 Apr 2011, 19:25

I don't know. I always wrap it in an if(smartfox.connected) check.
Devon
Posts: 41
Joined: 12 Apr 2011, 16:18

Postby Devon » 12 Apr 2011, 19:32

I was meaning to prevent a false negative... If there is a current connection attempt and my setTimeout expires, I'll be displaying a message saying the connection could not be established. However, 1 second later, the connection may finally get through and connect.

I want to be able to cancel the connection attempt with the timeout and provide the option to reconnect in the form of a button. In the same way that TinyChat handles their connections.

Let me know if I'm not making any sense at all, I've never used ActionScript, Flash, Flex, Java, ect... lol

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

Postby Lapo » 13 Apr 2011, 05:17

[P4E]Andy:
However, if the socket connection is never made, you will eventually get a socket timeout, and that won't come through the CONNECTION event. It could fail silently.

I always get a CONNECTION event even if I point to a non existing IP address or to a URL that has no SFS2X running on it.
It doesn't event take much time.

Maybe there's a version problem?

Code: Select all

private function onConnection(evt:SFSEvent):void
{
   if (evt.params.success)
   {
      dTrace("Connection Success!")
      sfs.send(new LoginRequest(ti_userName.text, "abcde"))
   }
   else
      dTrace("Connection Failure: " + evt.params.errorMessage)
   
}

In my code I trace the error, which always shows up:
--> Connection Failure: [IOErrorEvent type="ioError" bubbles=false cancelable=false eventPhase=2 text="Error #2031: Errore socket. URL: 192.168.0.111"]
Lapo
--
gotoAndPlay()
...addicted to flash games
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Postby Democre » 13 Apr 2011, 16:07

I think I may be wrong then. :oops:

Maybe it's a hold over. I do know that at one point there was a case when I didn't receive CONNECTION events from trying to connect to bad ip (either non-existant or no sfs). That's why I started coding that way.
Democre
Posts: 77
Joined: 16 Sep 2010, 17:58

Postby Democre » 13 Apr 2011, 20:52

Thinking about it some more, I think the original poster still has a problem.

His problem may have been what I encountered when I was first learning around smartfox, and I may have convinced myself that my explanation was what the problem was, and coded around it for myself.

I do indeed get connection refused errors through the CONNECTION event.

In any case, the original poster should be getting the error messages. If he is not, then something is wrong. Maybe too long a timeout at the socket level, I don't know. Sorry for the FUD.
-Andy

Return to “SFS2X ActionScript 3 API”

Who is online

Users browsing this forum: No registered users and 2 guests