libwebsocket and UE5 Packaged Build

I’m integrating the third-party libraries, libwebsockets from GitHub - warmcat/libwebsockets: canonical libwebsockets.org networking library
I want to create a websocket server inside the Unreal Engine, to make the library work I added the OpenSSL (the files that were required by libsocket to another thirdparty library folder) I got the SSL from Win32/Win64 OpenSSL Installer for Windows - Shining Light Productions

This is my buiid.cs

/

/ OpenSSL Integration
string OpenSSLPath = Path.Combine(ModuleDirectory, "..", "..", "ThirdParty", "OpenSSL");
PublicIncludePaths.Add(Path.Combine(OpenSSLPath, "Include"));
PublicAdditionalLibraries.Add(Path.Combine(OpenSSLPath, "Lib", "libcrypto.lib"));
PublicAdditionalLibraries.Add(Path.Combine(OpenSSLPath, "Lib", "libssl.lib"));

// libwebsockets Integration (Static Linking)
string LibWebSocketPath = Path.Combine(ModuleDirectory, "..", "..", "ThirdParty", "libwebsockets");
PublicIncludePaths.Add(Path.Combine(LibWebSocketPath, "Include"));
PublicAdditionalLibraries.Add(Path.Combine(LibWebSocketPath, "Lib", "websockets_static.lib"));

string ProjectDirectory = Path.GetFullPath(Path.Combine(ModuleDirectory, "../../"));

string BinariesWin64Path = Path.Combine(ProjectDirectory, "Binaries", "Win64");

// Add Runtime Dependencies for Windows
RuntimeDependencies.Add(Path.Combine(BinariesWin64Path, "websockets.dll"));
RuntimeDependencies.Add(Path.Combine(BinariesWin64Path, "libcrypto-3-x64.dll"));
RuntimeDependencies.Add(Path.Combine(BinariesWin64Path, "libssl-3-x64.dll"));

PublicDefinitions.Add("WITH_LIBWEBSOCKETS=1");
PublicDefinitions.Add("LWS_WITH_SSL=1");

PublicSystemLibraries.AddRange(new string[] { "Crypt32.lib", "Ws2_32.lib" });

What I am facing is that I am not able to start the server on the packaged build, I must add that my code is running fine as the server starts when I run it through Unreal editor in “Selected Window” or “Standalone” mode. I check that using the the command netstat -an | find "8080"

I get the port is listening when I run the code through editor but when I run it though the packaged build the port do not show up even though there are no errors in the log and it even provide me the log that the server is running. I even make sure to close the server when I quite, I tried this with multiple ports and I make extra sure to include the files in the package folder.

#include "WebSocketClient.h"
#include "Misc/ScopeLock.h"
#include "Misc/Char.h"

#define UI OPENSSL_UI
#include "libwebsockets.h"
#undef UI

FWebSocketClient::FWebSocketClient(lws* InWsi) : Wsi(InWsi)
{
}

FWebSocketClient ::~FWebSocketClient()
{
    Close();
}

void FWebSocketClient::SendMessageToWebSocket(const FString& Message)
{
    PendingMessages.Enqueue(Message);
    lws_callback_on_writable(Wsi);
}

void FWebSocketClient::ProcessWriteable()
{
    FString Message;
    if (PendingMessages.Dequeue(Message))
    {
        FTCHARToUTF8 Converter(*Message);
        const char* Utf8Data = Converter.Get();
        size_t DataSize = strlen(Utf8Data);

        size_t BufferSize = LWS_PRE + DataSize;
        uint8* Buffer = new uint8[BufferSize];
        memset(Buffer, 0, BufferSize);

        memcpy(&Buffer[LWS_PRE], Utf8Data, DataSize);

        int BytesWritten = lws_write(Wsi, &Buffer[LWS_PRE], DataSize, LWS_WRITE_TEXT);

        delete[] Buffer;

        if (BytesWritten < 0)
        {
            UE_LOG(LogTemp, Error, TEXT("LibWebSocketsPlugin:: Failed to send message to client"));
        }
    }
}

void FWebSocketClient::ProcessRead(const void* InData, SIZE_T InSize)
{
    FString Message = FString(FUTF8ToTCHAR(reinterpret_cast<const ANSICHAR*>(InData), InSize));

    if (OnMessageReceived.IsBound())
    {
        OnMessageReceived.Execute(AsShared(), Message);
    }
}

void FWebSocketClient::Close()
{
    if (Wsi)
    {
        // Close the WebSocket connection
        UE_LOG(LogTemp, Error, TEXT("LibWebSocketsPlugin:: Closing Client Connection"));
        lws_set_timeout(Wsi, PENDING_TIMEOUT_CLOSE_SEND, LWS_TO_KILL_ASYNC);
        Wsi = nullptr;
    }
}
FWebSocketServer::FWebSocketServer()
    : WebSocketContext(nullptr), Thread(nullptr), bRunning(false), bIsRunning(false), bStopRequested(false)
{
}

FWebSocketServer::~FWebSocketServer()
{
Stop()
}

bool FWebSocketServer::Start(int ServerPort)
{
    if (bRunning)
    {
        UE_LOG(LogTemp, Warning, TEXT("LibWebSocketsPlugin:: Server is already running."));
        return false;
    }

    WebSocketContext = nullptr;
    Thread = nullptr;

    Port = ServerPort;
    memset(&ContextCreationInfo, 0, sizeof(ContextCreationInfo));

    ContextCreationInfo.port = Port;
    ContextCreationInfo.protocols = Protocols;
    ContextCreationInfo.options = LWS_SERVER_OPTION_DISABLE_IPV6;
    ContextCreationInfo.user = this;
    ContextCreationInfo.iface = "127.0.0.1";

    WebSocketContext = lws_create_context(&ContextCreationInfo);
    if (!WebSocketContext)
    {
        UE_LOG(LogTemp, Error, TEXT("LibWebSocketsPlugin:: Failed to create WebSocket context."));
        return false;
    }

    // Start the thread
    Thread = FRunnableThread::Create(this, TEXT("FWebSocketServerThread"), 0, TPri_Normal);

    if (!Thread)
    {
        UE_LOG(LogTemp, Error, TEXT("LibWebSocketsPlugin:: Failed to create server thread."));
        lws_context_destroy(WebSocketContext);
        WebSocketContext = nullptr;
        bRunning = false;
        return false;
    }

    bRunning = true;
    bStopRequested = false;
    return true;
}

struct lws_protocols FWebSocketServer::Protocols[] = {
    {
        "websocket-protocol",   // Protocol name
        FWebSocketServer::CallbackWrapper, // Callback function
        0,             // Per session data size
        4096,          // Maximum frame size
    },
    { NULL, NULL, 0, 0 } // Terminator
};

void FWebSocketServer::Stop()
{
    UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: Going To close server"));
    if (bRunning && !bStopRequested)
    {
        UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: Stopping WebSocket server..."));

        // Signal the thread to stop
        bStopRequested = true;
        bRunning = false;

        // Cancel any ongoing lws_service call
        lws_cancel_service(WebSocketContext);

        // Wait for the thread to finish
        if (Thread)
        {
            UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: Waiting for server thread to finish..."));
            Thread->WaitForCompletion();
            delete Thread;
            Thread = nullptr;
            UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: Server thread has exited."));
        }

        CloseAllClients();

        // Destroy the WebSocket context
        if (WebSocketContext)
        {
            UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: Destroying WebSocket context..."));
            lws_context_destroy(WebSocketContext);
            WebSocketContext = nullptr;
            UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: WebSocket context destroyed."));
        }

        UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: WebSocket server stopped."));
    } 
}

uint32 FWebSocketServer::Run()
{
    UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: WebSocket server thread started."));
    while (bRunning)
    {
        int service_result = lws_service(WebSocketContext, 1000);
        if (service_result < 0)
        {
            UE_LOG(LogTemp, Error, TEXT("LibWebSocketsPlugin:: lws_service returned error: %d"), service_result);
            break;
        }
    }

    UE_LOG(LogTemp, Log, TEXT("LibWebSocketsPlugin:: WebSocket server thread exiting."));
    return 0;
}

void FWebSocketServer::CloseAllClients()
{
    FScopeLock Lock(&ClientsMutex);
    for (auto& Client : ConnectedClients)
    {
        if (Client.IsValid())
        {
            Client->Close();
        }
    }
    ConnectedClients.Empty();
}

These are my two classes

Again, I am getting positive logs in build where it says that the server ran but it is not running as the port didn’t show up in the netstat -an | find "8080" command. Please let me know if anyone can help me resolve this issue, I would appreciate this greatly. Please ask if there is any confusion in my description