Advertisement
Guest User

ZVT

a guest
Aug 6th, 2014
754
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.56 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3.  
  4. void connect( std::string host , unsigned int port );
  5. void sendAmount( std::string amount );
  6.  
  7.  
  8. std::stringstream               *ss;
  9. boost::asio::io_service         *io_service;
  10. boost::asio::ip::tcp::socket    *socketIO;
  11. size_t                          *sent;
  12.  
  13. // Verbindungsfunktion
  14. void connectTerminal( std::string host , unsigned int port )
  15. {
  16.     std::cout << "Connecting..." << std::endl;
  17.  
  18.     try
  19.     {
  20.         io_service  = new boost::asio::io_service;
  21.         socketIO    = new boost::asio::ip::tcp::socket( *io_service );
  22.            
  23.         socketIO->connect( boost::asio::ip::tcp::endpoint( boost::asio::ip::address::from_string( host ) , port ) );
  24.  
  25.         if( socketIO->is_open( ) )
  26.         {
  27.             std::cout << "Sending..." << std::endl;
  28.             sendAmount( "1234" );
  29.         }
  30.         else
  31.         {
  32.             std::cout << "Socket is closed..." << std::endl;
  33.         }
  34.     }
  35.     catch( std::exception &exc )
  36.     {
  37.         std::cerr << " [ Connection ] : " << exc.what() << std::endl;
  38.     }
  39. }
  40.  
  41.  
  42. // Geld an Terminal schicken
  43. void sendAmount( std::string amount )
  44. {
  45.     size_t  sent;
  46.  
  47.     ss = new std::stringstream;
  48.  
  49.     try
  50.     {
  51.         boost::array<uint8_t , 10>  money = { 0x06 , 0x01 , 0x07 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x69 };
  52.         boost::system::error_code   ignored_error;
  53.  
  54.         sent = boost::asio::write( *socketIO , boost::asio::buffer( money ) , boost::asio::transfer_all() , ignored_error );
  55.  
  56.         if( !sent )
  57.         {
  58.             std::cout << "Error: habe keine Daten gesendet!" << std::endl;
  59.         }
  60.  
  61.         socketIO->close( );
  62.     }
  63.     catch( std::exception &exc )
  64.     {
  65.         std::cerr << " [ Writing ] : " << exc.what() << std::endl;
  66.     }
  67.  
  68.     if( ss != NULL )
  69.     {
  70.         delete ss;
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement