Cant get winsock library to link correctly

I have tried to get this to work for hours, have looked through every google and forum post out there, and it still wont work. One of the forum post suggested using a “header sandwich” which i tried, and it gets it to allow the winsock header to be included correctly, but then the linker wont actually link the library, and it gives the lnk2019 error, saying it cant find any of the winsock functions.

.CPP:

#include “Client.h”

#include <winsock2.h>
#include

#pragma comment(lib, “Ws2_32.lib”)

// Sets default values
AClient::AClient()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.
PrimaryActorTick.bCanEverTick = true;

}

// Called when the game starts or when spawned
void AClient::BeginPlay()
{
Super::BeginPlay();

//Initialize Winsock
WSADATA ws;
if (WSAStartup(MAKEWORD(2, 2), &ws) != 0) {
	UE_LOG(LogTemp, Warning, TEXT("TEST"));
}

}

// Called every frame
void AClient::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);

}

.H:
#pragma once

#include “CoreMinimal.h”
#include “GameFramework/Actor.h”
#include “Client.generated.h”

UCLASS()
class MYPROJECT_API AClient : public AActor
{
GENERATED_BODY()

public:
// Sets default values for this actor’s properties
AClient();

protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;

public:
// Called every frame
virtual void Tick(float DeltaTime) override;

};

If you are including Windows stuff you need a “header sandwich” to instruct Unreal to prevent the macro/define collisions. Been using this over 5+ projects and works from Unreal 4.9 to 5.1:

// put this at the top of your .h file above #includes
// UE5: allow Windows platform types to avoid naming collisions
// must be undone at the bottom of this file!
#include "AllowWindowsPlatformTypes.h"
#include "prewindowsapi.h"

… your
… header
… file
… content

// put this at the bottom of the .h file
// UE5: disallow windows platform types
// this was enabled at the top of the file
#include "PostWindowsApi.h"
#include "HideWindowsPlatformTypes.h"

There’s a few old threads about this but added it here.