User Disconnect then Reconnect Error
User Disconnect then Reconnect Error
Hey SFS2X Team,
I have a AS3 client side I wish to allow a user to be able to disconnect and also reconnect from. However I am receiving an Error #2032: Stream Error. URL: http://127.0.0.1:0/BlueBox/BlueBox.do
As you can see this is a local server.
Steps:
1) Client Auto Loads sfs-config_http.xml
2) User can then manually connect and when they do so it connects
3) On Connection client side auto logs in for the user giving the user a guest account.
3) User can then manually disconnect and does so. "SmartFox.disconnect"
4) User can then manually trigger the same connect trigger. "SmartFox.connect()" Client side auto fills in the HOST and PORT from the SmartFox.config.host and SmartFox.config.port.
Then I get the before mentioned error.
Is this forum of re-connection not allowed or is there a delay preset to not allow connection spam to the server? If so is there a way to config that or for the client side to receive that info so I can set up a timer to allow the re-connection after the delay has passed?
I have a AS3 client side I wish to allow a user to be able to disconnect and also reconnect from. However I am receiving an Error #2032: Stream Error. URL: http://127.0.0.1:0/BlueBox/BlueBox.do
As you can see this is a local server.
Steps:
1) Client Auto Loads sfs-config_http.xml
2) User can then manually connect and when they do so it connects
3) On Connection client side auto logs in for the user giving the user a guest account.
3) User can then manually disconnect and does so. "SmartFox.disconnect"
4) User can then manually trigger the same connect trigger. "SmartFox.connect()" Client side auto fills in the HOST and PORT from the SmartFox.config.host and SmartFox.config.port.
Then I get the before mentioned error.
Is this forum of re-connection not allowed or is there a delay preset to not allow connection spam to the server? If so is there a way to config that or for the client side to receive that info so I can set up a timer to allow the re-connection after the delay has passed?
So...
So what your saying is if I want to be able to have the user disconnect themselves and say return at a later time with out having to relaunch the client side is that I need to set up a new SmartFox object during each connection scenario?
The user already has the ability to log-out and back in in my client side. However being that it is a guest log-in so they always log-in and get new user id's anyways.
I just wouldn't want to maintain a connection to the server if there is no need and I thought that having to reload the config file was a little redundant but I am guessing that is just how it is?
The user already has the ability to log-out and back in in my client side. However being that it is a guest log-in so they always log-in and get new user id's anyways.
I just wouldn't want to maintain a connection to the server if there is no need and I thought that having to reload the config file was a little redundant but I am guessing that is just how it is?
-
JimmiQR
- Posts: 39
- Joined: 03 Jan 2009, 01:08
- Location: Boston, Massachusetts, United States of America
- Contact:
Re: User Disconnect then Reconnect Error
I found this thread with the exact same concern, but wouldn't creating a new SmartFox object render all listeners attached to it orphaned?
If I disconnect(), or reboot/cycle the server, I would like all the clients to reconnect to the server again, without action from the user. I have a singleton class wrapper for my SmartFox instance, that I can then add listeners to anywhere in my project classes. I just go Server.getInstance(). So I can interact with my SmartFox object from anywhere.
but I also have listeners on that instance as well.
So as far as I can tell, my singleton structure doesn't allow me to create a new SFS object, which in turn doesn't allow me to re-connect to the server with out an entire page refresh.
Unless I am missing something?? Is there a programming struct I am not aware of to maintain these listeners?
Can't I just re-request the security policy file on this existing instance? Just go through the connection flow again (get config, policy file, connect, handshake, login, join zone, join room)?
If I disconnect(), or reboot/cycle the server, I would like all the clients to reconnect to the server again, without action from the user. I have a singleton class wrapper for my SmartFox instance, that I can then add listeners to anywhere in my project classes. I just go Server.getInstance(). So I can interact with my SmartFox object from anywhere.
Code: Select all
Server.getInstance().send(...
Server.getInstance().connect();
//etcCode: Select all
Server.getInstance().addEventListener(SFSEvent.EXTENSION_RESPONSE, extensionResponseHandler);
Server.getInstance().addEventListener(SFSEvent.ROOM_VARIABLES_UPDATE, roomVariablesUpdateHandler);
//etcUnless I am missing something?? Is there a programming struct I am not aware of to maintain these listeners?
Can't I just re-request the security policy file on this existing instance? Just go through the connection flow again (get config, policy file, connect, handshake, login, join zone, join room)?
Re: User Disconnect then Reconnect Error
Yes, that's correct.JimmiQR wrote:I found this thread with the exact same concern, but wouldn't creating a new SmartFox object render all listeners attached to it orphaned?
If you organize your code correctly by separating the creation of the SmartFox instance from the setup of the listeners you just need one line of code to recreate the instance and then you call the method that sets up your new listeners.
The problem is: you cannot know from client side if the server was rebooted, crashed, or your local network dropped or something in between kicked you out. If you just detect a disconnection and attempt to reconnect again you will end up with clients that never go awayIf I disconnect(), or reboot/cycle the server, I would like all the clients to reconnect to the server again, without action from the user. I have a singleton class wrapper for my SmartFox instance, that I can then add listeners to anywhere in my project classes. I just go Server.getInstance(). So I can interact with my SmartFox object from anywhere.
Since AS3 is not multithreaded you can safely invoke a reset() method on the singleton which internally creates a new instance.So as far as I can tell, my singleton structure doesn't allow me to create a new SFS object, which in turn doesn't allow me to re-connect to the server with out an entire page refresh.
-
JimmiQR
- Posts: 39
- Joined: 03 Jan 2009, 01:08
- Location: Boston, Massachusetts, United States of America
- Contact:
Re: User Disconnect then Reconnect Error
Ok, I will begin to go with this method of recreating a new SFS object upon a new connection in my Singleton. But I am still confused as to how this will be as easy as one line of code in my Singleton to set up my new listeners on this new object. Do one of the SmartFox sample codes that come with the setup utilize this technique?
You see, my singleton doesn't attach any listeners, but rather I have a bunch of classes that attach listeners. A chat panel, a game panel, a player panel, etc. And more to come. They listen for extensionResponses, and public and private message responses, and room updates. How would my singleton go about telling all these classes they need to re-attach their listeners? Or do I need a different way to attach them, using some overridden structure...
I know this is now beyond the scope of SmartFox help, since I am really asking about a coding structure now, but I am trying to avoid going down the road of adding hoop-jumping code to all my classes when what I really want is just the Server.getInstance().connect() to just work a second time. I realize there may be reasons such as complexity or security as to why this is the case, so I won't harp on that. But what is the clean way of having all my classes know that they must now reattach all of their listeners to this new Singleton object? If there really is some sample laying around, I would gladly dig through that.
You see, my singleton doesn't attach any listeners, but rather I have a bunch of classes that attach listeners. A chat panel, a game panel, a player panel, etc. And more to come. They listen for extensionResponses, and public and private message responses, and room updates. How would my singleton go about telling all these classes they need to re-attach their listeners? Or do I need a different way to attach them, using some overridden structure...
I know this is now beyond the scope of SmartFox help, since I am really asking about a coding structure now, but I am trying to avoid going down the road of adding hoop-jumping code to all my classes when what I really want is just the Server.getInstance().connect() to just work a second time. I realize there may be reasons such as complexity or security as to why this is the case, so I won't harp on that. But what is the clean way of having all my classes know that they must now reattach all of their listeners to this new Singleton object? If there really is some sample laying around, I would gladly dig through that.
Re: User Disconnect then Reconnect Error
Hi.
A quick and dirty way of doing this is to listen to all SmartFox's Events that you use in your singleton, handle those events in the same function, and then dispatch them again. This way, on the rest of your application, you simply need to add the listeners to the singleton and not to the SmartFox instance.
A quick and dirty way of doing this is to listen to all SmartFox's Events that you use in your singleton, handle those events in the same function, and then dispatch them again. This way, on the rest of your application, you simply need to add the listeners to the singleton and not to the SmartFox instance.
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.
Portfolio: https://rjgtav.wordpress.com/
SFS Tutorials: http://sfs-tutor.blogspot.com/ - Discontinued. Some examples may be bugged.
Re: User Disconnect then Reconnect Error
I could reply with another question. How would you go about telling all those components to clear their current state because the connection was closed and we need to start over? I guess the same mechanism applies for re-attaching the listeners.You see, my singleton doesn't attach any listeners, but rather I have a bunch of classes that attach listeners. A chat panel, a game panel, a player panel, etc. And more to come. They listen for extensionResponses, and public and private message responses, and room updates. How would my singleton go about telling all these classes they need to re-attach their listeners?
-
JimmiQR
- Posts: 39
- Joined: 03 Jan 2009, 01:08
- Location: Boston, Massachusetts, United States of America
- Contact:
Re: User Disconnect then Reconnect Error
Hey Lapo, Thanks for the responses.
Yes, some of my components may need to know to refresh their state, but not all of them. For instance, I wouldn't want my chat window to refresh, erasing the chat log just because of a re-connection, so no need to even tell it to redraw. I am either going to turn off BlueBox for now, or use rjgtav's quick and dirty method of first handling SFS events internal to my singleton all of the events my project uses, and having the singleton re-dipatch them, which allows me to add listeners to my singleton static class, and not my Singleton.getInstance. But this is a sloppy approach, as I have to remember to include any new events inside my singleton as well.
But that aside, I have been testing with this, and I have to say I feel it is an actual bug somewhere in com.smartfoxserver.v2.SmartFox. I made a simple interface to CONNECT, DISCONNECT, TOGGLE BLUEBLOX, and CREATE NEW SMARTFOX INSTANCE (supplied in code below). The bug can be replicated by making an attempt to connect to a non-reachable server with the blue box. Once it fails with the blue box, it will never succeed with socket or bluebox ever again. BUT, if you never attempt+and+fail a blue box connection, you can always connect to the server using the connect() whenever the server is back up. It is like a state machine, that once it gets to a failed Bluebox attempt, it can never get out of that broken state. No way to tell it to reset. It appears to cerate a session, but never send the handshake or login. You suggested we just new the SmartFox instance, but couldn't this bug either be tracked down, or add a reset() function to SmartFox allowing it to clean itself up internally?
This state machine will continue to work successfully.
Similar bug being reported can be found here:
Socket Error -> kill client for ever http://forums.smartfoxserver.com/viewtopic.php?t=13726
bug on reconnection http://forums.smartfoxserver.com/viewtopic.php?t=10205
Yes, some of my components may need to know to refresh their state, but not all of them. For instance, I wouldn't want my chat window to refresh, erasing the chat log just because of a re-connection, so no need to even tell it to redraw. I am either going to turn off BlueBox for now, or use rjgtav's quick and dirty method of first handling SFS events internal to my singleton all of the events my project uses, and having the singleton re-dipatch them, which allows me to add listeners to my singleton static class, and not my Singleton.getInstance. But this is a sloppy approach, as I have to remember to include any new events inside my singleton as well.
But that aside, I have been testing with this, and I have to say I feel it is an actual bug somewhere in com.smartfoxserver.v2.SmartFox. I made a simple interface to CONNECT, DISCONNECT, TOGGLE BLUEBLOX, and CREATE NEW SMARTFOX INSTANCE (supplied in code below). The bug can be replicated by making an attempt to connect to a non-reachable server with the blue box. Once it fails with the blue box, it will never succeed with socket or bluebox ever again. BUT, if you never attempt+and+fail a blue box connection, you can always connect to the server using the connect() whenever the server is back up. It is like a state machine, that once it gets to a failed Bluebox attempt, it can never get out of that broken state. No way to tell it to reset. It appears to cerate a session, but never send the handshake or login. You suggested we just new the SmartFox instance, but couldn't this bug either be tracked down, or add a reset() function to SmartFox allowing it to clean itself up internally?
This state machine will continue to work successfully.
- No server running
- run client
- click BlueBox toggle, set it to false
- click Connect, wait a few seconds for it to create session, but never log in and fail socket connection
- run server
- click Connect, SUCCESS and Login!
- close server
- goto and repeat at step 4
- No server running
- run client
- click BlueBox toggle, set it to true
- click Connect, wait a few seconds for it to create session, but never log in and fail socket connection, as well as fail http blue box conection
- run server
- click Connect, FAIL.
- nothing seems to get the client out of this dead end state such as trying to set useBlueBox back to false, hitting disconnect to clean up, etc. The only thing short of a browser refresh is clicking on New Instance, which I am trying to avoid for 'listener' reasons
- AS3 client 1.1.1
Flash players 11,2,202,235, 11.3.31.232, 11,4,402,265, as well as debug
swf published for 9.0, 10.0, 10.3, 11.0, and 11.1; same results
Chrome version 21, (but it may be even higher in the next couple of minutes)
Code: Select all
package {
import com.smartfoxserver.v2.core.SFSEvent;
import com.smartfoxserver.v2.requests.LoginRequest;
import com.smartfoxserver.v2.SmartFox;
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.text.TextField;
public class Main extends Sprite {
private var _smartFox:SmartFox;
private var _toggleBlueBoxTextField:TextField = new TextField();
public function Main():void {
init();
draw();
}
private function init():void {
_smartFox = new SmartFox();
_smartFox.addEventListener(SFSEvent.CONNECTION, connectionHandler);
_smartFox.addEventListener(SFSEvent.CONFIG_LOAD_SUCCESS, configLoadSuccessHandler);
_smartFox.loadConfig("sfs-config", false);
}
private function draw():void {
var connectTextField:TextField = new TextField();
connectTextField.addEventListener(MouseEvent.MOUSE_DOWN, connectTextFieldHandler);
connectTextField.text = "[connect]";
addChild(connectTextField);
var disconnectTextField:TextField = new TextField();
disconnectTextField.addEventListener(MouseEvent.MOUSE_DOWN, disconnectTextFieldHandler);
disconnectTextField.text = "[disconnect]";
addChild(disconnectTextField);
disconnectTextField.y = 20;
addChild(_toggleBlueBoxTextField);
_toggleBlueBoxTextField.y = 60;
_toggleBlueBoxTextField.text = "BlueBox (config xml not loaded yet...]"
_toggleBlueBoxTextField.addEventListener(MouseEvent.MOUSE_DOWN, toggleBlueBoxHandler);
var newInstanceTextField:TextField = new TextField();
newInstanceTextField.addEventListener(MouseEvent.MOUSE_DOWN, newInstanceTextFieldHandler);
newInstanceTextField.text = "[new instance]";
addChild(newInstanceTextField);
newInstanceTextField.y = 100;
}
private function configLoadSuccessHandler(event:SFSEvent):void {
trace("config loaded");
_toggleBlueBoxTextField.text = "[BlueBox is " + _smartFox.useBlueBox + "]";
}
private function connectTextFieldHandler(mouseEvent:MouseEvent):void {
trace("attempting connect...");
_smartFox.connect("127.0.0.1", 9933);
}
private function disconnectTextFieldHandler(mouseEvent:MouseEvent):void {
trace("attempting disconnect...");
_smartFox.disconnect();
}
private function toggleBlueBoxHandler(mouseEvent:MouseEvent):void {
_smartFox.useBlueBox = !_smartFox.useBlueBox;
TextField(mouseEvent.target).text = "[BlueBox is " + _smartFox.useBlueBox + "]";
}
private function connectionHandler(sfsEvent:SFSEvent):void {
if (sfsEvent.params.success == true) {
trace(" connected");
_smartFox.send(new LoginRequest());
}
else {
trace(" disconnected");
}
}
private function newInstanceTextFieldHandler(mouseEvent:MouseEvent):void {
init();
}
}
}Socket Error -> kill client for ever http://forums.smartfoxserver.com/viewtopic.php?t=13726
bug on reconnection http://forums.smartfoxserver.com/viewtopic.php?t=10205
Re: User Disconnect then Reconnect Error
Hi,
thanks for the long report. The client API are designed so that each instance is used for one session and then discarded, so it's not possible to use it the way you ask.
You can use weak references in your listeners to avoid removing them manually and when you need to restart the application you can re-run the method that attaches the listeners to your components.
Thanks
thanks for the long report. The client API are designed so that each instance is used for one session and then discarded, so it's not possible to use it the way you ask.
You can use weak references in your listeners to avoid removing them manually and when you need to restart the application you can re-run the method that attaches the listeners to your components.
Thanks