Examples

Hello World (C++)

Sending a payload defined in Unreal is easy with WebSock, here's how:


1. Define your payload

In your IDE create a USTRUCT as normal; note that desired members of the JSON payload should be marked UPROPERTY to interop with Unreal's property system.

Alternatively, you could use a pre-existing structure defined in C++ or Blueprints.

USTRUCT(BlueprintType)
struct FFoo 
{
    GENERATED_BODY()  
      
    // sent
    UPROPERTY(BlueprintReadOnly, VisibleAnywhere)
    int32 UPropField;
    
    // not sent
    int32 RegularField; 
}

UHT Metadata like BlueprintReadOnly and VisibleAnywhere is advised but not required


2. Send<T> via UWebSockSystem

UWebSockSystem::Get lets us pass in a UWorld context to manage connections with UWebSockSystem.

auto WebSock = UWebSockSystem::Get(GetWorld());
if (auto Connection = WebSock->NewSocket("ws://127.0.0.1"))
{
	Connection->Send<FFoo>({123, 456}); // 456 is not sent
}

Above, the second field: 456 is not sent over wire as it lacks the UPROPERTY decorator

Previous
Polymorphic Serialisation
© Hench Technology Ltd