SocketIOClient-Unreal icon indicating copy to clipboard operation
SocketIOClient-Unreal copied to clipboard

OnDisconnect not getting fired and reconnect even with bShouldAutoConnect = false;

Open cattomic opened this issue 9 years ago • 3 comments

Hi, I have been using this plugin for a while and is awesome, but there are two things I cant get to work: I successfully bind function with OnConnect: SIOClientComponent->OnConnected.AddDynamic(this, &UfpsGameInstance::OnClientWsConnect); where OnClientWsConnect is defined as: UFUNCTION() void OnServerWsConnect(FString SessionId);

but it doesnt work at all with OnDisconnect: SIOClientComponent->OnDisconnected.AddDynamic(this, &UfpsGameInstance::OnClientWsDisconnect); where OnClientWsDisconnect is defined as: UFUNCTION() void OnClientWsDisconnect(TEnumAsByte<ESIOConnectionCloseReason> Reason);

SIOClientComponent->OnSocketNamespaceDisconnected.AddDynamic(this, &UfpsGameInstance::OnClientWsDisconnect) doesnt work neither.

And no matter I set SIOClientComponent->bShouldAutoConnect = false; it keeps reconnecting when server is again available and then sends all the messages not delivered.

Can you help me?

cattomic avatar Jul 25 '17 17:07 cattomic

You need to set bShouldAutoConnect before begin play happens for it to take effect. e.g. in your parent/owner class constructor. You should also be able to call SIOClientComponent->Disconnect() at any time to stop your component from reconnecting.

As for the bound connections, have you tried the blueprint equivalent versions and confirmed that these work as expected?

Another option is to go down one level and use the FSocketIONative class which the component implements in https://github.com/getnamo/socketio-client-ue4/blob/master/Source/SocketIOClient/Private/SocketIOClientComponent.cpp#L140 to forward the events getting fired. But this is a workaround, if you have time, consider making a minimum project which allows for easy replication of the problem.

getnamo avatar Jul 25 '17 21:07 getnamo

I have in my GameInstance constructor: SIOClientComponent = CreateDefaultSubobject<USocketIOClientComponent>(TEXT("SocketIOClientComponent")); SIOClientComponent->bShouldAutoConnect = false;

I have tryed setting it to false even in your USocketIOClientComponent constructor... but it keep reconnecting when the server is available again.

About the disconnected event, I have tryed it in bp too, but I only get the event when I call disconnect, not when I got disconnected, for example, closing my node.js server.

You should also be able to call SIOClientComponent->Disconnect() at any time to stop your component from reconnecting. Right, but I cant do it if I dont know I lost my connection.

cattomic avatar Jul 26 '17 12:07 cattomic

Fixed in https://github.com/getnamo/socketio-client-ue4/commit/f17df08192bdebbae0b0cdabe96fe645e27bccc7.

The new architecture has a new callback called OnConnectionProblems. By default the plugin will attempt re-connections an infinite amount of time so OnDisconnect never gets called in the case of a server being closed. You can now detect this state by subscribing to the above function which also gives you details such as time since last connection etc etc.

The other reconnection issue should now also be fixed, re-open the issue if you find that new architecture still has this problem.

getnamo avatar Nov 11 '17 07:11 getnamo