### C++ ObjectDeliverer TCP/IP Server Initialization and Event Handling Source: https://github.com/ayumax/objectdeliverer/blob/master/README.md This C++ code snippet demonstrates how to initialize the ObjectDeliverer manager, bind event handlers for connection, disconnection, and data reception, and start a TCP/IP server on port 9099. It also includes a basic example of sending data. ```cpp void UMyClass::Start() { auto deliverer = UObjectDelivererManager::CreateObjectDelivererManager(); // Set up event handlers deliverer->Connected.AddDynamic(this, &UMyClass::OnConnect); deliverer->Disconnected.AddDynamic(this, &UMyClass::OnDisConnect); deliverer->ReceiveData.AddDynamic(this, &UMyClass::OnReceive); // Start communication // Protocol: TCP/IP Server // Data division rule: Header(Size) + Body // Serialization method: Byte array deliverer->Start(UProtocolFactory::CreateProtocolTcpIpServer(9099), UPacketRuleFactory::CreatePacketRuleSizeBody()); } void UMyClass::OnConnect(UObjectDelivererProtocol* ClientSocket) { // Send data TArray buffer; deliverer->Send(buffer); } void UMyClass::OnDisConnect(UObjectDelivererProtocol* ClientSocket) { // Handle disconnection UE_LOG(LogTemp, Log, TEXT("closed")); } void UMyClass::OnReceive(UObjectDelivererProtocol* ClientSocket, const TArray& Buffer) { // Handle received data } ``` -------------------------------- ### Clone ObjectDeliverer Repository from GitHub Source: https://github.com/ayumax/objectdeliverer/blob/master/README.md Command to clone the ObjectDeliverer GitHub repository to obtain the plugin source code for free installation. ```bash git clone https://github.com/ayumax/ObjectDeliverer.git ``` -------------------------------- ### Checkout Specific Unreal Engine Version Branch Source: https://github.com/ayumax/objectdeliverer/blob/master/README.md Example command to switch to a specific branch of the ObjectDeliverer repository, ensuring compatibility with a particular Unreal Engine version (e.g., UE5.4). ```bash git checkout UE5.4 ``` -------------------------------- ### Example: Custom Format JSON Output for CustomObject1 Source: https://github.com/ayumax/objectdeliverer/wiki/Selection-of-Json-serialize-method-in-ObjectDeliveryBoxUsingJson(Version-1.5.0-later) Provides an example of JSON output when using a custom serialization configuration for `CustomObject1`. This method allows selective inclusion of class names for specific properties, offering a balance between data size and deserialization flexibility based on `Default Serializer Type` and `Object Serializer Types` settings. ```json { "Prop2": 1, "ObjProp": { "Type": "CustomObjB_C", "Body": { "ValueB": 2, "ValueA": 3 } }, "ObjProp2": { "ValueC": "abc" } } ``` -------------------------------- ### Send and Receive UTF-8 Strings with ObjectDeliverer Source: https://github.com/ayumax/objectdeliverer/wiki/Change-of-Serialization-method This C++ example demonstrates how to configure ObjectDeliverer's DeliveryBox to send and receive UTF-8 encoded strings. It sets up a TCP/IP server, defines a packet rule, and registers a dynamic delegate for handling incoming string data. ```cpp // UTF-8 string auto deliverybox = UDeliveryBoxFactory::CreateUtf8StringDeliveryBox(); deliverybox->Received.AddDynamic(this, &UMyClass::OnReceiveString); deliverer->Start(UProtocolFactory::CreateProtocolTcpIpServer(9099), UPacketRuleFactory::CreatePacketRuleSizeBody(), deliverybox); deliverybox->Send(TEXT("ABCDEFG")); void UMyClass::OnReceiveString(FString ReceivedString) { // received data string } ``` -------------------------------- ### Example: Conventional JSON Output for CustomObject1 Source: https://github.com/ayumax/objectdeliverer/wiki/Selection-of-Json-serialize-method-in-ObjectDeliveryBoxUsingJson(Version-1.5.0-later) Demonstrates the JSON output when serializing a `CustomObject1` instance using the conventional format (without class names). This output is smaller but requires explicit target class specification during deserialization, potentially losing derived type information for nested objects like `ObjProp`. ```json { "Prop2": 1, "ObjProp": { "ValueB": 2, "ValueA": 3 }, "ObjProp2": { "ValueC": "abc" } } ``` -------------------------------- ### Send and Receive Objects (JSON) with ObjectDeliverer Source: https://github.com/ayumax/objectdeliverer/wiki/Change-of-Serialization-method This C++ example illustrates how to use ObjectDeliverer's DeliveryBox to send and receive custom objects serialized as JSON. It configures the DeliveryBox with a specific object class, sets up a TCP/IP server, and provides a handler for casting received generic objects to the expected type. ```cpp // Object(Json) auto deliverybox = UDeliveryBoxFactory::CreateObjectDeliveryBoxUsingJson(SampleObject::StaticClass()); deliverybox->Received.AddDynamic(this, &UMyClass::OnReceiveObject); deliverer->Start(UProtocolFactory::CreateProtocolTcpIpServer(9099), UPacketRuleFactory::CreatePacketRuleSizeBody(), deliverybox); auto obj = NewObject(); deliverybox->Send(obj); void UMyClass::OnReceiveObject(UObject* ReceivedObject) { // received data object USampleObject* obj = Cast(ReceivedObject); } ``` -------------------------------- ### Example: Class-Name-Included JSON Output for CustomObject1 Source: https://github.com/ayumax/objectdeliverer/wiki/Selection-of-Json-serialize-method-in-ObjectDeliveryBoxUsingJson(Version-1.5.0-later) Presents the JSON output when serializing a `CustomObject1` instance using the format that includes class names. This output is larger due to embedded type information but enables automatic polymorphic deserialization, preserving derived type information for nested objects such as `CustomObjB`. ```json { "Type": "CustomObject1_C", "Body": { "Prop2": 1, "ObjProp": { "Type": "CustomObjB_C", "Body": { "ValueB": 2, "ValueA": 3 } }, "ObjProp2": { "Type": "CustomObjC_C", "Body": { "ValueC": "abc" } } } } ``` -------------------------------- ### Understand ObjectDeliverer Git Branch Structure Source: https://github.com/ayumax/objectdeliverer/blob/master/README.md Illustrates the branching strategy used for the ObjectDeliverer repository, showing how the master branch aligns with the latest Unreal Engine version and specific branches are maintained for older UE versions. ```text master (latest UE version) ──┐ ├─ UE5.5 (UE5.5 specific) ├─ UE5.4 (UE5.4 specific) └─ UE5.3 (UE5.3 specific) ``` -------------------------------- ### Configure ObjectDeliverer Plugin in Unreal Project Source: https://github.com/ayumax/objectdeliverer/wiki/Sample-to-use-ObjectDeliverer's-C----file-in-your-project-class This JSON snippet illustrates the necessary configuration within the `.uproject` file to enable the ObjectDeliverer plugin. It specifies the engine association, module definitions, and explicitly enables the ObjectDeliverer plugin, ensuring it's loaded and available for use in the project. ```json { "FileVersion": 3, "EngineAssociation": "4.24", "Category": "", "Description": "", "Modules": [ { "Name": "IncludeOD", "Type": "Runtime", "LoadingPhase": "Default", "AdditionalDependencies": [ "CoreUObject" ] } ], "Plugins": [ { "Name": "ObjectDeliverer", "Enabled": true, "MarketplaceURL": "com.epicgames.launcher://ue/marketplace/content/c2612cff517c48bca7dd080299d97ca8" } ] } ``` -------------------------------- ### Configure ObjectDeliverer Communication Protocols Source: https://github.com/ayumax/objectdeliverer/wiki/Change-of-communication-protocol This C++ code snippet demonstrates how to initialize the ObjectDeliverer with various communication protocols. It covers setting up TCP/IP as a server or client, UDP as a sender or receiver, shared memory for inter-process communication, and log files for data writing and reading. All configurations utilize a common packet rule for size-body parsing. ```cpp // TCP/IP Server deliverer->Start(UProtocolFactory::CreateProtocolTcpIpServer(9099), UPacketRuleFactory::CreatePacketRuleSizeBody()); // TCP/IP Client deliverer->Start(UProtocolFactory::CreateProtocolTcpIpClient("localhost", 9099, true), UPacketRuleFactory::CreatePacketRuleSizeBody()); // UDP Sender deliverer->Start(UProtocolFactory::CreateProtocolUdpSocketSender("localhost", 9099), UPacketRuleFactory::CreatePacketRuleSizeBody()); // UDP Receiver deliverer->Start(UProtocolFactory::CreateProtocolUdpSocketReceiver(9099), UPacketRuleFactory::CreatePacketRuleSizeBody()); // Shared Memory deliverer->Start(UProtocolFactory::CreateProtocolSharedMemory("memory_test", 1024), UPacketRuleFactory::CreatePacketRuleSizeBody()); // LogFile Writer deliverer->Start(UProtocolFactory::CreateProtocolLogWriter("log.bin", false), UPacketRuleFactory::CreatePacketRuleSizeBody()); // LogFile Reader deliverer->Start(UProtocolFactory::CreateProtocolLogReader("log.bin", false, true), UPacketRuleFactory::CreatePacketRuleSizeBody()); ``` -------------------------------- ### Add ObjectDeliverer Module Dependencies to Build.cs Source: https://github.com/ayumax/objectdeliverer/wiki/Sample-to-use-ObjectDeliverer's-C----file-in-your-project-class This C# code snippet demonstrates how to modify the `Build.cs` file for an Unreal Engine module to include the ObjectDeliverer module and its dependencies. By adding "ObjectDeliverer", "Json", and "JsonUtilities" to `PublicDependencyModuleNames`, the project gains access to the necessary libraries for compilation and linking. ```csharp public class IncludeOD : ModuleRules { public IncludeOD(ReadOnlyTargetRules Target) : base(Target) { PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Json", "JsonUtilities", "ObjectDeliverer" }); PrivateDependencyModuleNames.AddRange(new string[] { }); } } ``` -------------------------------- ### Convert UObject to/from JSON String in C++ Source: https://github.com/ayumax/objectdeliverer/wiki/Sample-to-use-ObjectDeliverer's-C----file-in-your-project-class This C++ code snippet provides utility functions for serializing Unreal Engine `UObject` instances to JSON strings and deserializing JSON strings back into `UObject`s. It leverages ObjectDeliverer's internal JSON serialization utilities (`ODJsonDeserializer`, `ODJsonSerializer`) to facilitate data exchange, demonstrating how to integrate these functionalities into custom C++ classes. ```cpp #include "StringObjectConverer.h" // Include the relative path from Public Directory of "ObjectDeliverer Plugin" #include "../Private/Utils/JsonSerializer/ODJsonDeserializer.h" #include "../Private/Utils/JsonSerializer/ODJsonSerializer.h" UObject* UStringObjectConverer::String2UObject(FString string, UClass* classType) { TSharedRef> JsonReader = TJsonReaderFactory::Create(string); TSharedPtr JsonObject = MakeShareable(new FJsonObject()); if (!FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid()) return nullptr; UODJsonDeserializer* Deserializer = NewObject(); UObject* createdObj = Deserializer->JsonObjectToUObject(JsonObject, classType); return createdObj; } FString UStringObjectConverer::UObject2String(UObject* packet) { UODJsonSerializer* Serializer = NewObject(); auto jsonObject = Serializer->CreateJsonObject(packet); FString OutputString; TSharedRef> Writer = TJsonWriterFactory<>::Create(&OutputString); FJsonSerializer::Serialize(jsonObject.ToSharedRef(), Writer); return OutputString; } ``` -------------------------------- ### Configure Packet Splitting Rules in ObjectDeliverer (C++) Source: https://github.com/ayumax/objectdeliverer/wiki/Change-of-data-division-rule This C++ code snippet illustrates different methods to define how incoming packets are split using the `UPacketRuleFactory`. It shows configurations for fixed-length packets, packets with a size header followed by a body, packets terminated by a specific symbol, and packets that are not divided. ```cpp // FixedSize deliverer->Start(UProtocolFactory::CreateProtocolUdpSocketReceiver(9099), UPacketRuleFactory::CreatePacketRuleFixedLength(1024)); // Header(BodySize) + Body deliverer->Start(UProtocolFactory::CreateProtocolUdpSocketReceiver(9099), UPacketRuleFactory::CreatePacketRuleSizeBody(4, ECNBufferEndian::Big)); // Split by terminal symbol deliverer->Start(UProtocolFactory::CreateProtocolUdpSocketReceiver(9099), UPacketRuleFactory::CreatePacketRuleTerminate({ 0x00 })); // Nodivision deliverer->Start(UProtocolFactory::CreateProtocolUdpSocketReceiver(9099), UPacketRuleFactory::CreatePacketRuleNodivision()); ``` -------------------------------- ### Custom UObject JSON Serialization Output Source: https://github.com/ayumax/objectdeliverer/wiki/How-to-change-property-name-when-serializing-UObject-with-Json(Version-1.5.0-or-later) This JSON snippet demonstrates the result of serializing a UObject after implementing the `IODConvertPropertyName` interface and the `ConvertUPropertyName` method. Property names have been remapped from their original UObject names (e.g., 'Prop2' to 'IntProperty') to custom JSON keys, showcasing the effect of the conversion logic. ```JSON { "IntProperty": 1, "ObjectPropertyA": { "ValueB": 0, "ValueA": 0 }, "ObjectPropertyB": { "ValueC": "abc" } } ``` -------------------------------- ### Conventional JSON Format (No Class Name) Source: https://github.com/ayumax/objectdeliverer/wiki/Selection-of-Json-serialize-method-in-ObjectDeliveryBoxUsingJson(Version-1.5.0-later) Illustrates the basic JSON serialization format where the class name is omitted. This format is compact but requires the deserializer to explicitly know the target type for proper reconstruction. ```json { "Prop": 1 } ``` -------------------------------- ### IODConvertPropertyName Interface and ConvertUPropertyName Method Source: https://github.com/ayumax/objectdeliverer/wiki/How-to-change-property-name-when-serializing-UObject-with-Json(Version-1.5.0-or-later) This section provides API documentation for the `IODConvertPropertyName` interface, which is crucial for customizing JSON property names during UObject serialization. It outlines the `ConvertUPropertyName` method, detailing its parameters, return type, and behavior for mapping UObject property names to desired JSON keys. ```APIDOC interface IODConvertPropertyName: ConvertUPropertyName(UPropertyName: string) -> string UPropertyName: The original property name of the UObject. Returns: The desired JSON property name. If an empty string is returned, the original UObject property name will be used. ``` -------------------------------- ### Default UObject JSON Serialization Output Source: https://github.com/ayumax/objectdeliverer/wiki/How-to-change-property-name-when-serializing-UObject-with-Json(Version-1.5.0-or-later) This JSON snippet illustrates the default serialization behavior of a UObject (CustomObject1) where property names like 'Prop2', 'ObjProp', and 'ObjProp2' are directly used as JSON keys. This is the output before any custom property name conversion is applied. ```JSON { "Prop2": 1, "ObjProp": { "ValueB": 0, "ValueA": 0 }, "ObjProp2": { "ValueC": "abc" } } ``` -------------------------------- ### JSON Format with Embedded Class Name Source: https://github.com/ayumax/objectdeliverer/wiki/Selection-of-Json-serialize-method-in-ObjectDeliveryBoxUsingJson(Version-1.5.0-later) Shows the JSON serialization format that includes a 'Type' field for the class name and a 'Body' for the object data. This allows for polymorphic deserialization of multiple types within a single DeliveryBox and preserves inheritance information, but it increases the overall data size. ```json { "Type": "SampleClassName", "Body": { "Prop": 1 } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.