Page 1 of 1

No error on a failed connection?

Posted: 12 Apr 2011, 16:27
by Devon
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

Posted: 12 Apr 2011, 17:25
by rjgtav
well, usually it takes some time until it quits and says that it cant connect. Not sure if this is what are u asking

Posted: 12 Apr 2011, 17:26
by Devon
Well, I kept the window open for several minutes and never received an error. :-/

Is there a way to set a timeout?

Posted: 12 Apr 2011, 19:05
by Democre
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.

Posted: 12 Apr 2011, 19:24
by Devon
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?

Posted: 12 Apr 2011, 19:25
by Democre
I don't know. I always wrap it in an if(smartfox.connected) check.

Posted: 12 Apr 2011, 19:32
by Devon
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

Posted: 13 Apr 2011, 05:17
by Lapo
[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"]

Posted: 13 Apr 2011, 16:07
by Democre
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.

Posted: 13 Apr 2011, 20:52
by Democre
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