Websockets and dedicated servers
Use Websockets in Unreal Engine dedicated server builds
Quick post!
I was having trouble using Websockets in Unreal Engine when building the project as a linux dedicated server. FWebSocketsModule::Get().CreateWebSocket
was erroring with a fatal error (invalid attempt to read memory) as FWebSocketsModule
was nullptr
on those builds. This was working happily in-editor.
The problem was that the module was not loaded for linux dedicated server build which can be fixed with the following before calling FWebSocketsModule::Get()
:
1
2
3
4
5
6
7
if (!FModuleManager::Get().IsModuleLoaded("WebSockets"))
{
FModuleManager::Get().LoadModule("WebSockets");
}
// Call `CreateWebSocket` as usual
Socket = FWebSocketsModule::Get().CreateWebSocket(ServerURL, ServerProtocol);
After FModuleManager::Get().LoadModule("WebSockets")
had been called the issue was resolved and the dedicated server build was able to connect to a websocket server how I expected it to.
This post is licensed under
CC BY 4.0
by the author.