- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
#include "header.hpp"
int main(int argc, char** argv) {
if ( argc != 4 ) {
std::cout << "client ip port 0/1 - sleed disabled/enabled" << std::endl;
return 0;
}
std::string ip = argv[1];
boost::uint16_t port = boost::lexical_cast<boost::uint16_t>(argv[2]);
bool wsleep = (argv[3][0] == '1');
std::cout << "sleep " << (wsleep?"enabled":"disabled") << std::endl;
FILE* in = fopen("client_in.log", "wb");
FILE* out= fopen("client_out.log", "wb");
if ( !out || !in ) {
std::cout << "can`t open file!" << std::endl;
return 1;
}
boost::asio::ip::tcp::endpoint endpoint(
boost::asio::ip::address::from_string(ip), port
);
boost::asio::io_service ios;
boost::shared_ptr<boost::asio::io_service::work> work(new boost::asio::io_service::work(ios));
boost::thread thread(boost::bind(&boost::asio::io_service::run, &ios));
boost::asio::ip::tcp::socket socket(ios);
socket.connect(endpoint);
boost::asio::socket_base::non_blocking_io non_blocking_io(true);
socket.io_control(non_blocking_io);
client_read(socket, in);
for ( size_t idx = 0; idx < 100000000; ++idx ) {
char* buf = new char[send_buffer_size];
sprintf(buf, "cs:%8dn", idx);
start_write(socket, buf, out);
if ( wsleep ) {
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
}
}
std::cout
<< "send data to server finished!" << std::endl
<< "waiting for all ask`s from server..." << std::endl;
work.reset();
while ( counter ) {
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
std::cout << "." << std::flush;
}
std::cout << std::endl << std::endl
<< "all ask`s received." << std::endl
<< "terminate client..." << std::endl;
socket.cancel();
socket.close();
thread.join();
fclose(in);
fclose(out);
}