Subversion Repositories HomeAutomation

Rev

Rev 1593 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1. #include <iostream>
  2.  
  3. #include <boost/bind.hpp>
  4.  
  5. #include "net/Manager.h"
  6. #include "net/Types.h"
  7.  
  8. using namespace atom;
  9.  
  10. net::Manager::Pointer NM = net::Manager::Instance();
  11.  
  12. void Main_SlotOnNewState(net::ClientId client_id, net::ClientState client_state)
  13. {
  14.     std::cout << "client:" << client_id << " - New state: " << client_state << std::endl;
  15. }
  16.  
  17. void Main_SlotOnNewData(net::ClientId client_id, net::Buffer data)
  18. {
  19.     std::string s(data.data());
  20.    
  21.     std::cout << "client:" << client_id << " - New data: " << s << std::endl;
  22.    
  23.     net::Buffer out_data = data;
  24.    
  25.    
  26.     NM->SendTo(client_id, out_data);
  27. }
  28.  
  29. int main(int argc, char **argv)
  30. {
  31.     std::cout << "connect slots" << std::endl;
  32.    
  33.     NM->ConnectSlots(boost::bind(&Main_SlotOnNewState, _1, _2), boost::bind(&Main_SlotOnNewData, _1, _2));
  34.    
  35.     std::cout << "connect" << std::endl;
  36.    
  37.     try
  38.     {
  39.         net::ServerId server_id = NM->StartServer(net::PROTOCOL_TCP, 2000);
  40.         /*
  41.         net::ClientId client_id_udp = NM->Connect(net::PROTOCOL_UDP, "192.168.1.250", 1100);
  42.        
  43.         std::cout << "connected" << std::endl;
  44.        
  45.         char c[2] = { 251, 0 };
  46.         */
  47.         //NM->SendTo(client_id_udp, std::string(c));
  48.     }
  49.     catch (std::exception e)
  50.     {
  51.         std::cerr << e.what() << std::endl;
  52.     }
  53.    
  54.     std::cout << "sleep" << std::endl;
  55.    
  56.     sleep(100000000);
  57.    
  58.     return 0;
  59. }
  60.