Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- void connect( std::string host , unsigned int port );
- void sendAmount( std::string amount );
- std::stringstream *ss;
- boost::asio::io_service *io_service;
- boost::asio::ip::tcp::socket *socketIO;
- size_t *sent;
- // Verbindungsfunktion
- void connectTerminal( std::string host , unsigned int port )
- {
- std::cout << "Connecting..." << std::endl;
- try
- {
- io_service = new boost::asio::io_service;
- socketIO = new boost::asio::ip::tcp::socket( *io_service );
- socketIO->connect( boost::asio::ip::tcp::endpoint( boost::asio::ip::address::from_string( host ) , port ) );
- if( socketIO->is_open( ) )
- {
- std::cout << "Sending..." << std::endl;
- sendAmount( "1234" );
- }
- else
- {
- std::cout << "Socket is closed..." << std::endl;
- }
- }
- catch( std::exception &exc )
- {
- std::cerr << " [ Connection ] : " << exc.what() << std::endl;
- }
- }
- // Geld an Terminal schicken
- void sendAmount( std::string amount )
- {
- size_t sent;
- ss = new std::stringstream;
- try
- {
- boost::array<uint8_t , 10> money = { 0x06 , 0x01 , 0x07 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x69 };
- boost::system::error_code ignored_error;
- sent = boost::asio::write( *socketIO , boost::asio::buffer( money ) , boost::asio::transfer_all() , ignored_error );
- if( !sent )
- {
- std::cout << "Error: habe keine Daten gesendet!" << std::endl;
- }
- socketIO->close( );
- }
- catch( std::exception &exc )
- {
- std::cerr << " [ Writing ] : " << exc.what() << std::endl;
- }
- if( ss != NULL )
- {
- delete ss;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement