简体   繁体   English

虚幻引擎 4 上的 Websockets?

[英]Websockets on Unreal Engine 4?

I am getting started with Unreal Engine 4 .我开始使用虚幻引擎 4 I come from Libgdx and I am familiarized using WebSockets clients in my games and NodeJS with 'ws' on the server.我来自 Libgdx,我熟悉在我的游戏中使用 WebSockets 客户端,并在服务器上使用带有“ws”的 NodeJS。

How ever, I can't find information about Websockets and Unreal Engine 4.但是,我找不到有关Websockets和 Unreal Engine 4 的信息。

I know that given that it is programmed with C++ you can add external static libraries to the unreal project.我知道鉴于它是用 C++ 编程的,您可以将外部 static 库添加到虚幻项目中。

Can I use this c++ websocket library?我可以使用这个 c++ websocket 库吗?

https://github.com/zaphoyd/websocketpp https://github.com/zaphoyd/websocketpp

Will it run on Windows, Mac and console?它会在 Windows、Mac 和控制台上运行吗?

I am not an expert of c++ and static libraries.我不是 c++ 和 static 库的专家。 Please help, thanks!请帮助,谢谢!

You can follow this tutorial on TCP Sockets. 您可以在TCP套接字上遵循本教程

You will need to make some changes on the code, as it doesn't run on UE 4.10 (the tutorial is originally from 2014). 您将需要对代码进行一些更改,因为它无法在UE 4.10上运行(本教程最初来自2014年)。

On the .h file define 2 timer handles: 在.h文件中,定义2个计时器句柄:

FTimerHandle TimerHandle_Connection;
FTimerHandle TimerHandle_Socket;

On the .cpp file, inside StartTCPReceiver(...) change the line where the timer is set to: 在.cpp文件中,在StartTCPReceiver(...)内部,将计时器设置为以下行:

GetWorldTimerManager().SetTimer(TimerHandle_Connection, this, &AYourClass::TCPConnectionListener, 0.01, true);

and on TCPConnectionListener(...) change the line where the timer is set to: 并在TCPConnectionListener(...)上将计时器设置为以下行:

GetWorldTimerManager().ClearTimer(TimerHandle_Connection);//optional, only if you want to stop listening for new connections
GetWorldTimerManager().SetTimer(TimerHandle_Socket, this, &AYourClass::TCPSocketListener, 0.01, true);

(Another option would be to thread these functions instead of having them in timers) (另一种选择是线程化这些功能,而不是将它们放在计时器中)

Just in case, if you are new to UE, don't add the code directly on the IDE. 以防万一,如果您不熟悉UE,请不要直接在IDE上添加代码。 Go to the Content Browser > Add New > New C++ Class. 转到内容浏览器>添加新>新建C ++类。 You can create a new class that inherits from Actor, and when you want to start to listen to connections, you spawn that Actor. 您可以创建一个继承自Actor的新类,并且当您想开始侦听连接时,可以生成该Actor。

You can use any websocket or third party asset with unreal engine.您可以将任何 websocket 或第三方资产与虚幻引擎一起使用。 You can simply add the headers in your Build.cs file using PrivateIncludePathModuleNames for example (there's also a public include path) and it takes an array of strings where each string is a folder essentially.例如,您可以简单地使用PrivateIncludePathModuleNames在 Build.cs 文件中添加标头(还有一个公共包含路径),它采用一个字符串数组,其中每个字符串本质上是一个文件夹。 If you want to add a library (lib) file you can just add it like this:如果你想添加一个库 (lib) 文件,你可以像这样添加它:

if (Target.Platform == UnrealTargetPlatform.Win32 ||
            Target.Platform == UnrealTargetPlatform.Win64)
{
            PublicSystemLibraries.Add("crypt32.lib");
}

You can also add full paths here.您还可以在此处添加完整路径。 If you want to do a delayed load you can just use PublicDelayLoadedDlls.Add("name") <- I may have the syntax wrong on this one but it's easy to google it.如果你想延迟加载,你可以只使用PublicDelayLoadedDlls.Add("name") <- 我可能在这个语法上有错误,但很容易用谷歌搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM