Skip to content

FrozenStormInteractive/Unreal-SignalR

Repository files navigation


Logo
SignalR for Unreal

Dependencies

This plug-in requires Visual Studio and either a C++ code project or a full Unreal Engine source code from GitHub.

This plugin does not support the MessagePack protocol for the moment, only the JSON protocol.

Usage

You can use this plug-in as a project plug-in, or an Engine plug-in:

  • If you use it as a project plug-in, clone this repository into your project's Plugins directory and compile your game in Visual Studio. A C++ code project is required for this to work.

  • If you use it as an Engine plug-in, clone this repository into the Engine/Plugins directory and compile your game. Full Unreal Engine source code from GitHub is required for this.

This plug-in is enabled by default, so no need to enable it in the plug-in browser.

Link the SignalR module to to yours with PublicDependencyModuleNames or PrivateDependencyModuleNames in <YourModule>.build.cs:

PrivateDependencyModuleNames.AddRange(new string[]
{
    "SignalR",
}
);

Create a hub connection with the SignalR engine subsystem:

#include "SignalRModule.h"
#include "IHubConnection.h"

TSharedPtr<IHubConnection> Hub = GEngine->GetEngineSubsystem<USignalRSubsystem>()->CreateHubConnection("https://example.com/chathub");

Bind an event which is fired when the server call it to the client.

Hub->On(TEXT("EventName")).BindLambda([](const TArray<FSignalRValue>& Arguments)
{
    ...
});

Invoke fires an event when the server has finished invoking the method (or an error occurred). In addition, the event can receive a result from the server method, if the server returns a result.

Hub->Invoke(TEXT("Add"), 1, 1).BindLambda([](const FSignalRInvokeResult& Result)
{
    if (!Result.HasError())
    {
        UE_LOG(LogTemp, Warning, TEXT("The result value is: %d"), Result.AsInt());
    }
});

Unlike the Invoke method, the Send method doesn't wait for a response from the server.

Hub->Send(TEXT("Add"), 1, 1);

Troubleshooting

Nothing happens when connecting to SignalR URL

Keep a reference to your connection with a shared pointer. If you don't do this, the connection object will be destroyed and therefore won't work.

Remember that the function IHubConnection::Start is asynchronous. When you send data after calling the function, the connection may not be complete (the data to be sent are kept on hold)

Negotiate failed with status code 307

LogSignalR: Error: Negotiate failed with status code 307

Redirections are not yet supported. Use IP address or a domain name without redirection.

You can also disable UseHttpsRedirection() in ASP.NET Core.

Peer certificate cannot be authenticated with given CA certificates

The HTTP module does not support self-signed certificates. The dotnet development certificate is not recognized by Unreal.

You can:

  • use the HTTP protocol (Disable UseHttpsRedirection() in ASP.NET Core)
  • or disable peer verification in Project Settings > Engine > Network > Verify Peer

Disable peer verification in Unreal Project Settings

Contributing

Please see CONTRIBUTING.md for instructions on how to contribute.

License

This project is licensed under the MIT License - see the LICENSE.txt file for details.

Copyright (c) 2020-2022 Frozen Storm Interactive, Yoann Potinet