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;
};