Hi Lapo,
I’ve worked a while at the problem. Cleared out some issues on our side.
Now the problem happens only in the second case. Meaning, if I put the APP back within the <10 sec pause> everything is fine. No problem there. But if the user gets disconnected (after the 10sec), and I get back to it, it throws the same SessionReconnectionException.
Now I do not expect the reconnection to work after the timeout has been reached. Of course the user has to re-connect and login again. But I don’t think this is normal, and the state in the client gets damaged by it.
I am using:
[SFS - INFO]SFS2X API version: 1.3.7
I did an experiment with your IOS examples to check if I can reproduce it with them. And yes, it’s there. I used the Connector example and changed only SFS2X_iOS_Examples/Connector/Connector/ViewController.m file. I am attaching it here. (below I describe the changes one by one)
I run SmartFoxServer 2X (2.9.0).
You can change the ViewController.m with this one.
In the BasicExamples Zone I’ve changed only the timeouts to be 10/30 like this:
<userReconnectionSeconds>10</userReconnectionSeconds>
<overrideMaxUserIdleTime>30</overrideMaxUserIdleTime>
Then. I run the app. It auto connects. The server sees the user. Everything is fine.
I put it on the background. Wait for the server to tell it disconnects the client.
Then put the app back active and the server gives the error.
Code: Select all
15:45:40,973 INFO [SocketReader] sessions.DefaultSessionManager - Session created: { Id: 5, Type: DEFAULT, Logged: No, IP: 192.168.1.113:50013 } on Server port: 9933 <---> 50013
15:45:40,987 INFO [SFSWorker:Sys:3] api.SFSApi - User login: { Zone: BasicExamples }, ( User Name: testme, Id: 4, Priv: 0, Sess: 192.168.1.113:50013 ) , Type: IOS version: 8.1.1
15:46:04,538 INFO [Scheduler1-thread-1] sessions.DefaultSessionManager - Session removed: { Id: 5, Type: DEFAULT, Logged: Yes, IP: 192.168.1.113:50013 }
15:46:04,539 INFO [SFSWorker:Sys:4] api.SFSApi - User disconnected: { Zone: BasicExamples }, ( User Name: testme, Id: 4, Priv: 0, Sess: 192.168.1.113:50013 ) , SessionLen: 23552, Type: IOS version: 8.1.1
15:46:15,252 INFO [SocketReader] sessions.DefaultSessionManager - Session created: { Id: 6, Type: DEFAULT, Logged: No, IP: 192.168.1.113:50021 } on Server port: 9933 <---> 50021
SENDING TO -------> { Id: 6, Type: DEFAULT, Logged: No, IP: 192.168.1.113:50021 }
15:46:15,276 INFO [SocketReader] sessions.DefaultSessionManager - Session removed: { Id: 6, Type: DEFAULT, Logged: No, IP: 192.168.1.113:50021 }
15:46:15,278 WARN [SFSWorker:Sys:3] v290.SystemReqController - com.smartfoxserver.bitswarm.exceptions.SessionReconnectionException: Session Reconnection failure. The passed Session is not managed by the ReconnectionManager: java.nio.channels.SocketChannel[connected local=/192.168.1.188:9933 remote=/192.168.1.113:50021]
com.smartfoxserver.bitswarm.sessions.DefaultReconnectionManager.reconnectSession(DefaultReconnectionManager.java:146)
com.smartfoxserver.bitswarm.sessions.DefaultSessionManager.reconnectSession(DefaultSessionManager.java:383)
com.smartfoxserver.v2.controllers.system.Handshake.execute(Handshake.java:68)
com.smartfoxserver.v2.controllers.v290.SystemReqController.processRequest(SystemReqController.java:157)
com.smartfoxserver.v2.controllers.v290.SystemReqController.enqueueRequest(SystemReqController.java:114)
com.smartfoxserver.bitswarm.io.protocols.AbstractProtocolCodec.dispatchRequestToController(AbstractProtocolCodec.java:39)
com.smartfoxserver.v2.protocol.SFSProtocolCodec.dispatchRequest(SFSProtocolCodec.java:125)
com.smartfoxserver.v2.protocol.SFSProtocolCodec.onPacketRead(SFSProtocolCodec.java:90)
com.smartfoxserver.v2.protocol.binary.BinaryIoHandler$1.run(BinaryIoHandler.java:525)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
java.lang.Thread.run(Thread.java:745)
The changes were with the idea to make it auto-reconnect and are the following lines:
Code: Select all
- (void)viewDidLoad
{
[super viewDidLoad];
smartFox = [[SmartFox2XClient alloc] initSmartFoxWithDebugMode:YES delegate:self];
smartFox.logger.loggingLevel = LogLevel_DEBUG;
[smartFox loadConfig:@"config.xml" connectOnSuccess:YES]; // changed line
}
Code: Select all
/**
* Log in to the zone configured in the config.xml
*/
- (IBAction)login:(id)sender
{
[self doLogin]; // changed line
}
// added new method to be used again
-(void) doLogin {
[smartFox send:[LoginRequest requestWithUserName:@"testme" password:@"" zoneName:nil params:nil]]; // changed line to add some username
loginBtn.enabled = NO;
}
Code: Select all
/**
* Connection Events
*/
- (void)onConnection:(SFSEvent *)evt
{
NSArray *keys = [evt.params allKeys];
for (NSString *key in keys) {
NSLog(@"%@: %@", key, [evt.params objectForKey:key]);
}
if ([[evt.params objectForKey:@"success"] boolValue])
{
[self trace:@"You are now connected to SFS2X"];
connectBtn.enabled = NO;
disconnectBtn.enabled = YES;
loginBtn.enabled = YES;
[self doLogin]; // added line
}
else
{
[self trace:[NSString stringWithFormat:@"Connection error: %@.", [evt.params objectForKey:@"error"]]];
connectBtn.enabled = YES;
}
}
Code: Select all
- (void)onConnectionLost:(SFSEvent *)evt
{
[self trace:@"You have been disconnected from SFS2X"];
connectBtn.enabled = YES;
disconnectBtn.enabled = NO;
loginBtn.enabled = NO;
logoutBtn.enabled = NO;
[smartFox connect]; // added line
connectBtn.enabled = NO; // added line
}
I saw IOS examples are old, with an old api. I can conduct an experiment with updated API, but I am sure I will recreate it again.
Here is the client log too:
Code: Select all
2014-12-11 15:45:41.327 Connector[339:33135] [SFS - INFO]SFS2X API version: 1.2.1
2014-12-11 15:45:41.686 Connector[339:33135] [SFS - INFO]sending handshake request: isReconnection : NO
2014-12-11 15:45:41.687 Connector[339:33135] [SFS - INFO]WRITE - Creating a new buffer
2014-12-11 15:45:41.688 Connector[339:33135] [SFS - INFO]Data Write: Binary Size: 61
80 00 3a 12 00 03 00 01 63 02 00 00 01 61 03 00 ..:.....c....a..
00 00 01 70 12 00 02 00 03 61 70 69 08 00 05 31 ...p.....api...1
2e 32 2e 31 00 02 63 6c 08 00 12 49 4f 53 20 76 .2.1..cl...IOS.v
65 72 73 69 6f 6e 3a 20 38 2e 31 2e 31 ersion:.8.1.1
2014-12-11 15:45:41.689 Connector[339:33135] [SFS - INFO]WRITE - Written directly to outStream len:61
2014-12-11 15:45:41.694 Connector[339:33135] [SFS - INFO]Data Read: Binary Size: 80
80 00 4d 12 00 03 00 01 61 03 00 00 00 01 63 02 ..M.....a.....c.
00 00 01 70 12 00 03 00 02 74 6b 08 00 20 63 65 ...p.....tk...ce
37 31 62 34 36 65 33 38 30 65 35 31 32 38 65 66 71b46e380e5128ef
61 63 34 36 34 64 36 33 63 31 32 30 32 36 00 02 ac464d63c12026..
63 74 04 00 00 04 00 00 02 6d 73 04 00 0f 42 40 ct.......ms...B@
2014-12-11 15:45:41.695 Connector[339:33135] [SFS - DEBUG]Handling New Packet
2014-12-11 15:45:41.695 Connector[339:33135] [SFS - DEBUG]Handling Header Size. Size: 79 (small)
2014-12-11 15:45:41.695 Connector[339:33135] [SFS - DEBUG]Handling Data: 77, previous state: 0 / 77
2014-12-11 15:45:41.695 Connector[339:33135] [SFS - DEBUG]<<< Packet Complete >>>
2014-12-11 15:45:41.696 Connector[339:33135] [SFS - INFO]Handling Message: Handshake: { Message id: 0 }
{Dump: }
(int) ms: 1000000
(utf_string) tk: ce71b46e380e5128efac464d63c12026
(int) ct: 1024
2014-12-11 15:45:41.696 Connector[339:33135] success: 1
2014-12-11 15:45:41.698 Connector[339:33135] [SFS - INFO]WRITE - Written directly to outStream len:63
2014-12-11 15:45:41.699 Connector[339:33135] [SFS - INFO]Data Write: Binary Size: 63
80 00 3c 12 00 03 00 01 63 02 00 00 01 61 03 00 ..<.....c....a..
01 00 01 70 12 00 03 00 02 70 77 08 00 00 00 02 ...p.....pw.....
7a 6e 08 00 0d 42 61 73 69 63 45 78 61 6d 70 6c zn...BasicExampl
65 73 00 02 75 6e 08 00 06 74 65 73 74 6d 65 es..un...testme
2014-12-11 15:45:41.709 Connector[339:33135] [SFS - INFO]Data Read: Binary Size: 131
80 00 80 12 00 03 00 01 61 03 00 01 00 01 63 02 ........a.....c.
00 00 01 70 12 00 06 00 02 72 6c 11 00 01 11 00 ...p.....rl.....
09 04 00 00 00 00 08 00 09 54 68 65 20 4c 6f 62 .........The.Lob
62 79 08 00 07 64 65 66 61 75 6c 74 01 00 01 00 by...default....
01 00 03 00 00 03 00 96 11 00 00 00 02 7a 6e 08 .............zn.
00 0d 42 61 73 69 63 45 78 61 6d 70 6c 65 73 00 ..BasicExamples.
02 72 73 03 00 0a 00 02 75 6e 08 00 06 74 65 73 .rs.....un...tes
74 6d 65 00 02 69 64 04 00 00 00 04 00 02 70 69 tme..id.......pi
03 00 00 ...
2014-12-11 15:45:41.709 Connector[339:33135] [SFS - DEBUG]Handling New Packet
2014-12-11 15:45:41.709 Connector[339:33135] [SFS - DEBUG]Handling Header Size. Size: 130 (small)
2014-12-11 15:45:41.710 Connector[339:33135] [SFS - DEBUG]Handling Data: 128, previous state: 0 / 128
2014-12-11 15:45:41.710 Connector[339:33135] [SFS - DEBUG]<<< Packet Complete >>>
2014-12-11 15:45:41.712 Connector[339:33135] [SFS - INFO]Handling Message: Login: { Message id: 1 }
{Dump: }
(short) rs: 10
(sfs_array) rl:
(sfs_array)
(int)0
(utf_string)The Lobby
(utf_string)default
(bool)0
(bool)0
(bool)0
(short)0
(short)150
(sfs_array)
(utf_string) zn: BasicExamples
(utf_string) un: testme
(int) id: 4
(short) pi: 0
2014-12-11 15:46:14.779 Connector[339:33135] [SFS - INFO]Reconnection attempt: 10 sec.
2014-12-11 15:46:15.968 Connector[339:33135] [SFS - INFO]sending handshake request: isReconnection : YES
2014-12-11 15:46:15.969 Connector[339:33135] [SFS - INFO]WRITE - Creating a new buffer
2014-12-11 15:46:15.970 Connector[339:33135] [SFS - INFO]Data Write: Binary Size: 100
80 00 61 12 00 03 00 01 63 02 00 00 01 61 03 00 ..a.....c....a..
00 00 01 70 12 00 03 00 03 61 70 69 08 00 05 31 ...p.....api...1
2e 32 2e 31 00 02 63 6c 08 00 12 49 4f 53 20 76 .2.1..cl...IOS.v
65 72 73 69 6f 6e 3a 20 38 2e 31 2e 31 00 02 72 ersion:.8.1.1..r
74 08 00 20 63 65 37 31 62 34 36 65 33 38 30 65 t...ce71b46e380e
35 31 32 38 65 66 61 63 34 36 34 64 36 33 63 31 5128efac464d63c1
32 30 32 36 2026
2014-12-11 15:46:15.971 Connector[339:33135] [SFS - INFO]WRITE - Written directly to outStream len:100
2014-12-11 15:46:15.989 Connector[339:33135] [SFS - INFO]Data Read: Binary Size: 23
80 00 14 12 00 03 00 01 61 03 03 ee 00 01 63 02 ........a.....c.
00 00 01 70 12 00 00 ...p...
2014-12-11 15:46:15.990 Connector[339:33135] [SFS - DEBUG]Handling New Packet
2014-12-11 15:46:15.990 Connector[339:33135] [SFS - DEBUG]Handling Header Size. Size: 22 (small)
2014-12-11 15:46:15.990 Connector[339:33135] [SFS - DEBUG]Handling Data: 20, previous state: 0 / 20
2014-12-11 15:46:15.990 Connector[339:33135] [SFS - DEBUG]<<< Packet Complete >>>
2014-12-11 15:46:15.991 Connector[339:33135] [SFS - INFO]Handling Message: ReconnectionFailure: { Message id: 1006 }
{Dump: }
2014-12-11 15:46:15.994 Connector[339:33135] [SFS - WARN]Already connected!
Tell me if you cannot reproduce it, or you need more info.
Thanks!