Advertisement
AlexNovoross87

Layserv

Jun 2nd, 2025
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.22 KB | None | 0 0
  1. #include "service.h"
  2. #include "tokenizer.h"
  3. #include <boost/asio.hpp>
  4. #include <iostream>
  5.  
  6. namespace net = boost::asio;
  7. using tcp = net::ip::tcp;
  8.  
  9. void test1()
  10. {
  11.  
  12. try{
  13.  
  14. net::io_context ioc(16);
  15. tcp::socket socket{ioc};
  16. boost::system::error_code ec;
  17. auto endpoint = tcp::endpoint(net::ip::make_address("127.0.0.1"), 80);
  18.  
  19. socket.open(endpoint.protocol(), ec);
  20. if (ec) {
  21. std::cerr << "Open error: " << ec.message() << std::endl;
  22. }
  23.  
  24. socket.set_option(boost::asio::socket_base::reuse_address(true), ec);
  25. if (ec) {
  26. std::cerr << "Set option error: " << ec.message() << std::endl;
  27. }
  28.  
  29. socket.connect(endpoint, ec);
  30. if (ec) {
  31. std::cerr << "COnnect error: " << ec.message() << std::endl;
  32. }
  33.  
  34. task mp;
  35. std::optional<std::string> reas = std::nullopt;
  36. std::string str = "";
  37. Service::TokenGen gen;
  38.  
  39. // boost::asio::io_context ioc;
  40. str = UserInterface::US_ChrMakeSendMessage(gen.GenerateHEXToken(), "22sssssssswdqeefvqwef222222222222222222222222222222");
  41.  
  42. net::post(ioc, [&](){
  43. net::write(socket,net::buffer(std::move(str)));
  44. });
  45.  
  46. str = UserInterface::US_ChrMakeObjDisconnect(gen.GenerateHEXToken());
  47. net::post(ioc, [&](){
  48. net::write(socket,net::buffer(std::move(str)));
  49. });
  50.  
  51. str = UserInterface::US_SrvMakeObjCreateRoom("YANDEX");
  52. net::post(ioc, [&](){
  53. net::write(socket,net::buffer(std::move(str)));
  54. });
  55.  
  56. str = UserInterface::US_SrvMakeObjCreateUser("RRAT", "hjsjklk;l");
  57. net::post(ioc, [&](){
  58. net::write(socket,net::buffer(std::move(str)));
  59. });
  60.  
  61. str = UserInterface::US_SrvMakeObjGetUsers("RRAT");
  62. net::post(ioc, [&](){
  63. net::write(socket,net::buffer(std::move(str)));
  64. });
  65.  
  66. str = UserInterface::US_SrvMakeObjLogin("RRAT", "jijjiw", "kjjolpdpw");
  67. net::post(ioc, [&](){
  68. net::write(socket,net::buffer(std::move(str)));
  69. });
  70.  
  71. str = UserInterface::US_SrvMakeObjRoomList();
  72. net::post(ioc, [&](){
  73. net::write(socket,net::buffer(std::move(str)));
  74. });
  75. Service::MtreadRunContext(ioc);
  76. }
  77. catch(const std::exception&ex){
  78. std::cout << ex.what();
  79. system("pause");
  80. }
  81.  
  82. // ioc.run();
  83.  
  84. }
  85.  
  86. int main()
  87. {
  88. for(int i = 0; i<5; ++i){
  89. test1();
  90. }
  91. /// system("pause");
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement