zoukankan      html  css  js  c++  java
  • UE4 nDisplay外部应用发送ClusterEvent

    private int SendClusterCommand(string nodeAddress, int port, string cmd, bool bQuiet = false)
            {
                int ResponseCode = 1;
                TcpClient nodeClient = new TcpClient();
    
                if (!bQuiet)
                {
                    AppLogger.Log(string.Format("Sending command {0} to {1}...", cmd, nodeAddress));
                }
    
                try
                {
                    // Connect to the listener
                    nodeClient.Connect(nodeAddress, port);
                    NetworkStream networkStream = nodeClient.GetStream();
    
                    byte[] OutData = ASCIIEncoding.ASCII.GetBytes(cmd);
                    byte[] OutSize = BitConverter.GetBytes((short)OutData.Length);
    
                    networkStream.Write(OutSize, 0, OutSize.Length);
                    networkStream.Write(OutData, 0, OutData.Length);
                    AppLogger.Log("Event sent");
    
                    byte[] InLength = new byte[2];
                    int InBytesCount = networkStream.Read(InLength, 0, 2);
                    AppLogger.Log("Received " + InBytesCount + " bytes");
    
                    int MessageSize = InLength[0] + ((UInt16)InLength[1] << 8);
                    byte[] InData = new byte[MessageSize];
                    InBytesCount = networkStream.Read(InData, 0, MessageSize);
                    AppLogger.Log("Received " + InBytesCount + " bytes");
    
                    string Response = ASCIIEncoding.ASCII.GetString(InData, 0, InBytesCount);
                    AppLogger.Log("Response " + Response);
                }
                catch (Exception ex)
                {
                    if (!bQuiet)
                    {
                        AppLogger.Log("An error occurred while sending a command to " + nodeAddress + ". EXCEPTION: " + ex.Message);
                    }
                }
                finally
                {
                    nodeClient.Close();
                }
    
                return ResponseCode;
            }

    出自UE4源码。

    cmd参数的构造:

    {

      "Category" : "",

      "Type" : "",

      "Name" : "",

      "Parameters":{},

    }

    名称(Name)类型(Type) 和 类别(Category) 字段为必填字段,但可以忽略参数(Parameters)字段。

    具体写法可以使用nDisplayLauncher发送一个Cluster Event然后看日志:

     

  • 相关阅读:
    大型网站核心架构因素
    大型网站架构模式
    博客中的文章归档是如何实现的
    Caused by: java.sql.SQLException: Value '0000-00-00 00:00:00' can not be represented as java.sql.Timestamp
    git分支开发的好处
    layui之日期和时间组件
    vue-electron脚手架
    springboot1.5.4 配置druid1.1.0(使用druid-spring-boot-starter)
    Node.js读取文件内容并返回值(非异步)
    C# ftp ListFilesOnServer
  • 原文地址:https://www.cnblogs.com/CodeSnippet/p/11375804.html
Copyright © 2011-2022 走看看