• 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然后看日志:

     

  • 相关阅读:
    数据处理之PostgreSQL过程语言学习
    Thinkphp中的assign() 和 display()
    JS截取与分割字符串常用技巧总结
    三种JS截取字符串方法
    十大经典排序算法的JS版
    js时间与毫秒互相转换
    javascript--清除表单缓存
    JS join()和split()方法、reverse() 方法、sort()方法
    JS数组去重的几种常见方法
    CSS样式大全
  • 原文地址:https://www.cnblogs.com/CodeSnippet/p/11375804.html
Copyright © 2020-2023  润新知