BlueMQTT.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using Blue;
  2. using UnityEngine;
  3. /// <summary>
  4. /// https://www.emqx.io/docs/zh/v5.1/faq/faq.html#emqx-%E5%90%AF%E5%8A%A8%E6%97%B6%E6%8F%90%E7%A4%BA%E7%AB%AF%E5%8F%A3%E8%A2%AB%E5%8D%A0%E7%94%A8-eaddrinuse-%E5%BA%94%E8%AF%A5%E6%80%8E%E4%B9%88%E5%8A%9E
  5. /// 1883 MQTT 协议端口
  6. /// 8883 MQTT/SSL 端口
  7. /// 8083 MQTT/WebSocket 端口
  8. /// 8084 MQTT/WSS (WebSocket/SSL) 端口,可通过配置修改
  9. /// 4370 用于 EMQX 分布式集群远程函数调用、Mnesia 数据同步等
  10. /// 5370 用于分担上一端口压力的集群 RPC 端口,主要用于节点间转发 MQTT 消息
  11. /// 18083 HTTP API 服务的默认监听端口,Dashboard 功能也依赖于这个端口,可通过配置修改
  12. /// </summary>
  13. public class BlueMQTT : AbstractController
  14. {
  15. [SerializeField] private string brokerAddress = "api-fat1.ghz-tech.com";
  16. [SerializeField] private int brokerPort = 1883;
  17. [SerializeField] private string mqttUserName = "u@unity3";
  18. private IMQTTService mQTTService;
  19. void Start()
  20. {
  21. mQTTService = this.GetService<IMQTTService>();
  22. mQTTService.brokerAddress = brokerAddress;
  23. mQTTService.brokerPort = brokerPort;
  24. mQTTService.mqttUserName = mqttUserName;
  25. }
  26. void Update()
  27. {
  28. mQTTService.Update();
  29. }
  30. private void OnApplicationQuit()
  31. {
  32. mQTTService.OnApplicationQuit();
  33. }
  34. }