中间件底层,websocket

RcfServer.cpp 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // RcfServer.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
  2. //
  3. #include <iostream>
  4. #include <thread>
  5. #include "RcfEcho.h"
  6. #include "RCF\RcfConfig.h"
  7. #include "CRedis.h"
  8. #include "HttpServer.h"
  9. // IsAlreadyRunning - 是否已经运行
  10. BOOL IsAlreadyRunning()
  11. {
  12. char _szAppName[] = "RcfServer";
  13. char _szTitle[] = "RcfServer";
  14. BOOL bRet = FALSE;
  15. HANDLE hMutex = ::CreateMutex(NULL, TRUE, _szAppName);
  16. if (GetLastError() == ERROR_ALREADY_EXISTS)
  17. {
  18. if (hMutex)
  19. {
  20. ::ReleaseMutex(hMutex);
  21. }
  22. bRet = TRUE;
  23. HWND hWnd = FindWindow(_szAppName, _szTitle);
  24. if (::IsIconic(hWnd)) ::ShowWindow(hWnd, SW_RESTORE); //SW_SHOW
  25. SetForegroundWindow(hWnd); // 将主窗激活
  26. ::SetForegroundWindow(::GetLastActivePopup(hWnd)); // 将主窗的对话框激活
  27. }
  28. return bRet;
  29. }
  30. int main(int argc, char **argv)
  31. {
  32. // 禁止多个实例的同时运行
  33. if (IsAlreadyRunning())
  34. {
  35. std::cout << "当前程序已运行,本次运行无效,请关闭当前窗口" << std::endl;
  36. system("pause");
  37. return 0;
  38. }
  39. try
  40. {
  41. RCF::RcfInit rcfInit;
  42. CRcfEcho echo;
  43. RCF::RcfServer server(RCF::TcpEndpoint("0.0.0.0", RcfConfig::GetInstance()->RcfPort()));
  44. server.bind<I_RcfEcho>(echo, "agent");
  45. server.setThreadPool(RCF::ThreadPoolPtr(new RCF::ThreadPool(1, 5)));
  46. server.start();
  47. std::cout << "RCF服务启动..." << "0.0.0.0 " << RcfConfig::GetInstance()->RcfPort() << std::endl;
  48. if (!CRedis::GetInstance()->connect(RcfConfig::GetInstance()->RedisIP().c_str(), RcfConfig::GetInstance()->RedisPort(), ""))
  49. std::cout << "redis 连接失败!" << std::endl;
  50. HttpServer httpServer;
  51. httpServer.run(RcfConfig::GetInstance()->HttpPort(), RcfConfig::GetInstance()->HttpsPort());
  52. while (true)
  53. {
  54. std::this_thread::sleep_for(std::chrono::hours(24));
  55. }
  56. }
  57. catch (const RCF::Exception & e)
  58. {
  59. std::cout << e.getErrorMessage() << std::endl;
  60. std::cout << "3秒后自动关闭" << std::endl;
  61. std::this_thread::sleep_for(std::chrono::seconds(3));
  62. return 0;
  63. }
  64. return 0;
  65. }