Sign In Register

How can we help you today?

Start a new topic
Answered

RTSession and Unreal 4: Duplicated packets

 Hello,

I'm using RTSessions with Unreal 4. The server is authoritative: the clients just send messages to the server and it sends back to the client the info that is updated.

I am having some strange behaviour with the packets.

First, the Match is launched (and the Session created) when 2 players send the MatchmakingRequest (1v1). The session is correctly created and the script runs as expected.

Simplifying it, when the server receives a packet with OpCode 002, it sends it back to the client who sent it with some information added (for testing purposes, we add also the id of the RTSession).

So, in a clean scenario this works perfect: the server receives the packet and the client receives the response as it can be seen here (bad formatting due to Unreal log but here it is):

image



But, now I close both clients and launch them again (doing authentication, matchmaking and creating the Session). When a client sends the packet 002, it receives *two*  responses, one with the new session id and one with the last session id:

image



If I close the clients and launch them again, it receives three packets and so on... (I guess there's a Timeout for the Sessions since they die at some point).

So, the obvious response is that the disconnection is not being made correctly, but the server receives both OnPlayerDisconnect messages (I can't see any function in the API to destroy the Session when both players are disconnected so I guessed this was made automatically, isn't it? How to close the Session?)

Furthermore, on the Shutdown method of the GameInstance on the Unreal Client Code (called before the game is closed) there is a:
 

if(gameSession.IsValid() && gameSession->Ready)
{
  gameSession->Stop();
}

 which actually makes nothing because if it's commented the behaviour is exactly the same.

Even furthermore, there's a button on the GUI of the game that sends the client back to the lobby (it should disconnect from the session in order to be able to join to another one via matchmaking) that, in its onClick it does:

 

void ATestRoomGameMode::ExitSession() const
{
  auto MyGameInstance = Cast<UMyGameInstance>(GetWorld()->GetGameInstance());
  //GameSession pointer is stored in the GameInstance
  MyGameInstance->gameSession->Stop();

  //This just sends the client back to the Launcher
  UGameplayStatics::OpenLevel(GetWorld(), "Launcher");
}

 

So Stop() is called in the session pointer. This is not firing OnPlayerDisconnect either in the server nor in the other client. Is Stop() really intended to make the player be disconnected from the Session? How is this made?

Thank you and best regards,
Ignacio


Best Answer

Hey,


It was my problem.


The problem was that the file with the class that was in charge of doing the packet communication was being imported through:

require('./Network);


And the export was:


var Network = (function(){
    ....
})();

module.exports = Network;

 

Which is a Singleton of the object. The problem is how CommonJS cache works. It considers a hit of the cache whenever it would be resolve the same **file** on the FileSystem, so, absurdly this object was being shared between sessions...


Sorry for the false negative.


Still, the ->Stop() function is not working as expected, if I'm not wrong. Calling .reset() on the SharedPointer of Unreal4 it's working correctly.


Thanks and very best,

Ignacio


Answer

Hey,


It was my problem.


The problem was that the file with the class that was in charge of doing the packet communication was being imported through:

require('./Network);


And the export was:


var Network = (function(){
    ....
})();

module.exports = Network;

 

Which is a Singleton of the object. The problem is how CommonJS cache works. It considers a hit of the cache whenever it would be resolve the same **file** on the FileSystem, so, absurdly this object was being shared between sessions...


Sorry for the false negative.


Still, the ->Stop() function is not working as expected, if I'm not wrong. Calling .reset() on the SharedPointer of Unreal4 it's working correctly.


Thanks and very best,

Ignacio

Hello, Ignacio.

thanks for sharing your answer.

I'm using Unity, can you please tell me where is the .reset() function? is it in GameSparks unreal API? 

Sorry, I haven't used unreal before.


Login to post a comment