Hi.
I’m having some issues sending a UDP packet with UE4. I want to implement a server-browser ping requet using it. I’ve got the server browser… the ping just doesn’t send. I’ve added 5 test servers, all of which point to a local lan ip with random 5 random ports.
I’ve tried using SetIP() on the ip address objects and using the int32 ip forms on CreateInternetAddr().
Below is my correct local lan ip. I’ve tried binding to any address (0.0.0.0) for that and using a specific port.
I’m using the return of the function (false/-1) and wireshark on this pc and sniffit on my other one to detect the packets… they are not being sent.
Any ideas?
Here’s my code:
ISocketSubsystem* oSocketSubsystem = ISocketSubsystem::Get( PLATFORM_SOCKETSUBSYSTEM );
FSocket* oSocket = oSocketSubsystem->CreateSocket( NAME_DGram, "UDP Ping Socket", true );
oSocket->SetBroadcast( false );
oSocket->SetNonBlocking( true );
oSocket->SetReuseAddr( false );
int iSize = 1024;
oSocket->SetSendBufferSize( iSize, iSize );
oSocket->SetReceiveBufferSize( iSize, iSize );
auto oLocalAddr = oSocketSubsystem->CreateInternetAddr();
bool bValid;
oLocalAddr->SetIp( L"192.168.1.3", bValid );
oLocalAddr->SetPort( 0 );
if ( !oSocket->Bind( *oLocalAddr ) )
return 0;
FUDPPingDataPacket uPacket;
uPacket.stValues.iRefreshId = iRefreshId;
for ( int i = 0; bContinuePinging && i < arServerRows.Num(); ++i )
{
FString strAddress = /* stuff */;
TArray<FString> arAddress;
strAddress.ParseIntoArray( &arAddress, L":", false );
if ( arAddress.Num() != 2 )
continue;
int32 iPort = FPlatformString::Atoi( *arAddress[ 1 ] );
if ( iPort < 0 || iPort > 65534 )
continue;
auto oRemoteAddr = oSocketSubsystem->CreateInternetAddr();
oRemoteAddr->SetIp( *arAddress[ 0 ], bValid );
oRemoteAddr->SetPort( iPort + 1 );
int32 iSent = 0;
oSocket->SendTo( uPacket.arData, 8, iSent, *oRemoteAddr );
}
delete oSocket;
return 0;