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

     

  • 相关阅读:
    七周七语言——Prolog(二)
    centos中使用python遇到的几个问题
    use SWF / Flash in cocos2d-x; cocos2d(cocos2d-x) 直接播放flash / SWF文件
    【C++自我精讲】基础系列二 const
    Find发帖水王哥
    JAVA从零单排之前因
    CSharp
    python实战--Http代理服务器
    有道单词-批量导入[只有单词]
    编译原理(一道小证明题)
  • 原文地址:https://www.cnblogs.com/CodeSnippet/p/11375804.html
Copyright © 2011-2022 走看看