Skip to content

Commit

Permalink
Fix for UE Network
Browse files Browse the repository at this point in the history
  • Loading branch information
sammyfreg committed Nov 17, 2024
1 parent 5d0ab0a commit ab9d516
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
11 changes: 11 additions & 0 deletions Code/Client/Private/NetImgui_NetworkPosix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@
#include <unistd.h>
#include <fcntl.h>

//NOTE: The socket handling has been modified to improve speed, but the Posix version
// has not been updated. Please review the changes made to 'NetImgui_NetworkWin32.cpp'
// between version 1.11 and 1.12 and bring them over to this file. In particular :
// -Sockets set to non blocking and immediate sending
// -Added 'DataReceivePending' function
// -Reworked 'DataReceive' and 'DataSend' to be non blocking socket operation
// but wait until all data has been processed
// -Connect now handle timeout instead of letting the socket timeout internally
// after a long time
static_assert(0)

namespace NetImgui { namespace Internal { namespace Network
{

Expand Down
30 changes: 15 additions & 15 deletions Code/Client/Private/NetImgui_NetworkUE4.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "NetImgui_Shared.h"

// Tested with Unreal Engine 4.27, 5.0, 5.2
// Tested with Unreal Engine 4.27, 5.0, 5.2, 5.3, 5.4

#if NETIMGUI_ENABLED && defined(__UNREAL__)

Expand Down Expand Up @@ -63,31 +63,31 @@ void Shutdown()
//=================================================================================================
SocketInfo* Connect(const char* ServerHost, uint32_t ServerPort)
{
SocketInfo* pSocketInfo = nullptr;
ISocketSubsystem* SocketSubSystem = ISocketSubsystem::Get();
auto ResolveInfo = SocketSubSystem->GetHostByName(ServerHost);

while( ResolveInfo && !ResolveInfo->IsComplete() ){
FPlatformProcess::YieldThread();
}

if ( ResolveInfo && ResolveInfo->GetErrorCode() == 0)
SocketInfo* pSocketInfo = nullptr;
ISocketSubsystem* SocketSubSystem = ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM);
TSharedPtr<FInternetAddr> IpAddressFind = SocketSubSystem->GetAddressFromString((TCHAR*)StringCast<TCHAR>(static_cast<const ANSICHAR*>(ServerHost)).Get());
if(IpAddressFind)
{
TSharedRef<FInternetAddr> IpAddress = ResolveInfo->GetResolvedAddress().Clone();
TSharedRef<FInternetAddr> IpAddress = IpAddressFind->Clone();
IpAddress->SetPort(ServerPort);
if (IpAddress->IsValid())
{
FSocket* pNewSocket = SocketSubSystem->CreateSocket(NAME_Stream, "NetImgui", IpAddress->GetProtocolType());
if (pNewSocket)
{
pNewSocket->SetNonBlocking(true);
if (pNewSocket->Connect(IpAddress.Get()))
if (pNewSocket->Connect(*IpAddress))
{
pSocketInfo = netImguiNew<SocketInfo>(pNewSocket);
return pSocketInfo;
bool bConnectionReady = false;
pNewSocket->WaitForPendingConnection(bConnectionReady, FTimespan::FromSeconds(1.0f));
if( bConnectionReady )
{
pSocketInfo = netImguiNew<SocketInfo>(pNewSocket);
return pSocketInfo;
}
}
}
}
}
}
netImguiDelete(pSocketInfo);
return nullptr;
Expand Down
2 changes: 1 addition & 1 deletion Code/ServerApp/Source/NetImguiServer_Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ void NetworkConnectRequest_Send()
{
NetImguiServer::Config::Client::SetProperty_ConnectRequest(clientConfig.mRuntimeID, false, false); // Reset the Connection request, we are processing it
NetImguiServer::Config::Client::SetProperty_Status(clientConfig.mRuntimeID, NetImguiServer::Config::Client::eStatus::Disconnected);
clientConfigID = clientConfig.mRuntimeID; // Keep track of ClientConfig we are attempting to connect to
clientConfigID = clientConfig.mRuntimeID; // Keep track of ClientConfig we are attempting to connect to
pClientSocket = NetImgui::Internal::Network::Connect(clientConfig.mHostName, clientConfig.mHostPort);
}
}
Expand Down

0 comments on commit ab9d516

Please sign in to comment.