中间件底层,websocket

YamlConfig.cpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #include "stdafx.h"
  2. #include "YamlConfig.h"
  3. YamlConfig::YamlConfig()
  4. {
  5. try
  6. {
  7. YAML::Node node = YAML::LoadFile(YAMLCONFIGFILEPATH);
  8. if (node["WsServer"])
  9. {
  10. this->wsServerIP = node["WsServer"]["IP"].as<string>();
  11. this->wsServerPort = node["WsServer"]["PORT"].as<int>();
  12. }
  13. if (node["ACD"])
  14. {
  15. this->acdIP = node["ACD"]["IP"].as<string>();
  16. this->acdPort = node["ACD"]["PORT"].as<int>();
  17. }
  18. if (node["HttpServer"])
  19. {
  20. this->httpIP = node["HttpServer"]["IP"].as<string>();
  21. this->httpPort = node["HttpServer"]["PORT"].as<int>();
  22. }
  23. if (node["Wss"])
  24. {
  25. this->sslFilePath = node["Wss"]["SSL"].as<string>();
  26. this->sslPwd = node["Wss"]["PWD"].as<string>();
  27. this->wssPort = node["Wss"]["PORT"].as<int>();
  28. }
  29. }
  30. catch (const std::exception&)
  31. {
  32. // 配置文件 读取异常,重新初始化配置文件
  33. YAML::Node node;
  34. std::ofstream fout(YAMLCONFIGFILEPATH);
  35. node["WsServer"]["IP"] = "127.0.0.1";
  36. node["WsServer"]["PORT"] = 8811;
  37. node["ACD"]["IP"] = "127.0.0.1";
  38. node["ACD"]["PORT"] = 8821;
  39. node["HttpServer"]["IP"] = "0.0.0.0";
  40. node["HttpServer"]["PORT"] = "8081";
  41. node["Wss"]["SSL"] = "server.pem";
  42. node["Wss"]["PWD"] = "123456";
  43. node["Wss"]["PORT"] = 8082;
  44. fout << node;
  45. fout.close();
  46. this->wsServerIP = node["WsServer"]["IP"].as<string>();
  47. this->wsServerPort = node["WsServer"]["PORT"].as<int>();
  48. this->acdIP = node["ACD"]["IP"].as<string>();
  49. this->acdPort = node["ACD"]["PORT"].as<int>();
  50. this->httpIP = node["HttpServer"]["IP"].as<string>();
  51. this->httpPort = node["HttpServer"]["PORT"].as<int>();
  52. this->sslFilePath = node["Wss"]["SSL"].as<string>();
  53. this->sslPwd = node["Wss"]["PWD"].as<string>();
  54. this->wssPort = node["Wss"]["PORT"].as<int>();
  55. }
  56. }
  57. YamlConfig::~YamlConfig()
  58. {
  59. }
  60. YamlConfig YamlConfig::sp;