How to check the current connection is alive?

Hi,

I need a way to check if a client is succesfully connected to the server and viceversa, is there any way to check it?

My problem is that I have an online game, and I use the event “NetworkError” to clean the sessions on the clients and servers, when server shuts down or lose the connection (if I don’t do that, then clients are not able to create new sessions, because “there is already a session with that name”). But then, the problem is when the clients have a bit of lag or a microcuts, that fire the event, and force the client to exit the sesion instantly, when it should wait some time to check if the connection is really lost or it was a just some seconds of bad internet connection, like a persistent connection for some time.

Any Ideas or workaround about this?
thx in advance :slight_smile:

Hi,

I don’t know if UE4 has this kind of feature. But you can implement a “ping/pong” system yourself easily using UE4 network features.

For example:

  1. Client start a timer and call a server RPC function “Server_ping()”
  2. The server now knows the client is alive
  3. Server then call the client RPC function “Client_pong()”.The client now knows the connection is alive.
  4. If the client never get the “Client_pong()” call, let’s randomly say, withing a second (using the timer), then consider the connection lost ?

This can be done in both ways I guess.

Good luck. Best regards :slight_smile:

Hello,

First look at ESocketConnectionState

	TCPSocket->Connect(*address);

	if (TCPSocket->GetConnectionState() != ESocketConnectionState::SCS_Connected)
	{
		GLog->Log("USocketObject::InitSocket --- No connection"); 
	}

But in my client I sending a message to the server every second (use threads or timers ), if the message did not reach the server is offline. Messages are the same and if the server no longer receive messages from the client, the client is offline.

bIsСonnection = TCPSocket->Send((uint8*)TCHAR_TO_UTF8(serializedChar), size, sent);
1 Like