ue4中 cpp文件
// Fill out your copyright notice in the Description page of Project Settings.
#include “MyActor.h”
#include
#include “Object.h”
#include “Runtime/Networking/Public/Networking.h”
// Sets default values
AMyActor::AMyActor()
{
// 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;
SocketClient = NULL;
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
void AMyActor::EndPlay(const EEndPlayReason::Type EndPlayReason)
{
Super::EndPlay(EndPlayReason);
UWorld* World = GetWorld();
GetWorld()->GetTimerManager().ClearTimer(TCPConnectionListenerTimerHandle);
GetWorld()->GetTimerManager().ClearTimer(TCPSocketListenerTimerHandle);
if (ConnectionSocket != NULL) {
ConnectionSocket->Close();
}
if (ListenerSocket != NULL) {
ListenerSocket->Close();
}
if (SocketClient) {
SocketClient->Close();
ISocketSubsystem::Get(PLATFORM_SOCKETSUBSYSTEM)->DestroySocket(SocketClient);
}
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
bool AMyActor::SocketCreate(FString IPStr, int32 port) {
FIPv4Address::Par