Last active
May 6, 2017 07:51
-
-
Save ryanjon2040/21cbb0397f7ea520d23bd0ce66109a39 to your computer and use it in GitHub Desktop.
Example source file for pinging EC2 UDp server http://wp.me/p2fInN-tA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void UYourGameInstance::CheckIfServerIsOnline(FString ServerIP, FString ServerPort) | |
{ | |
/* First bind our OnServerCheckFinished function to PingResult. | |
* When we get any reply from UDP server PingResult will be called | |
* and when PingResult is called the binded method (OnServerCheckFinished) is also called. */ | |
PingReult.BindUObject(this, &UYourGameInstance::OnServerCheckFinished); | |
/* Our UDP server ip (public ip) and port we have to ping. | |
* Port should be the exact same port we defined on UDP server node.js file on EC2 server */ | |
const FString Address = FString::Printf(TEXT("%s:%d"), *ServerIP, ServerPort); | |
// Finally just ping. | |
FUDPPing::UDPEcho(Address, 5.f, PingReult); | |
} | |
void UYourGameInstance::OnServerCheckFinished(FIcmpEchoResult Result) | |
{ | |
// Unbind the function. Its no longer required. | |
PingReult.Unbind(); | |
// Simply set a status. | |
FString PingStatus = "Ping Failed"; | |
// Do your stuff based on the result. | |
switch (Result.Status) | |
{ | |
case EIcmpResponseStatus::Success: | |
PingStatus = "Success"; | |
break; | |
case EIcmpResponseStatus::Timeout: | |
PingStatus = "Timeout"; | |
break; | |
case EIcmpResponseStatus::Unreachable: | |
PingStatus = "Unreachable"; | |
break; | |
case EIcmpResponseStatus::Unresolvable: | |
PingStatus = "Unresolvable"; | |
break; | |
case EIcmpResponseStatus::InternalError: | |
PingStatus = "Internal Error"; | |
break; | |
default: | |
PingStatus = "Unknown Error"; | |
break; | |
} | |
// Simple log | |
UE_LOG(LogTemp, Display, "Ping Result is " + PingStatus); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment