UE5 C++的TCP客户端示例

发布时间:2024年01月14日

 客户端.h

需要在Build.cs中加入模块:"Networking","Sockets","Json","JsonUtilities"

// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "ClientActorClass.generated.h"

UCLASS()
class TCPSERVERANDCLIENT_API AClientActorClass : public AActor
{
	GENERATED_BODY()

public:
	// Sets default values for this actor's properties
	AClientActorClass();

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

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

	static FSocket* Socket;

	//"Networking","Sockets"
	UFUNCTION(BlueprintCallable,Category = "TCPServerAndClient")
	static bool ClientConnectToTCPServer(const FString& IP,int32 Port = 8888);

	UFUNCTION(BlueprintCallable,Category = "TCPServerAndClient")
	static bool SendDataFormClicentToServer(TArray<uint8> SendData);

	UFUNCTION(BlueprintCallable,Category = "TCPServerAndClient")
	static bool DisConnectFormClientToServer();

	UFUNCTION(BlueprintCallable,Category = "TCPServerAndClient")
	static TArray<uint8> ReceiveDataFromTCPServer();

	//"Json","JsonUtilities"
	UFUNCTION(BlueprintCallable,Category = "TCPServerAndClient")
	static void StringToBytes(FString InString,bool& OutBool,TArray<uint8>& OutBytesArray);

	UFUNCTION(BlueprintCallable,Category = "TCPServerAndClient")
	static void DataTypeToJSON(int32 Int,bool Inbool,F
文章来源:https://blog.csdn.net/weixin_42318094/article/details/135581957
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。