Fixed some dumb bugs. Think I may have been asleep for last push.

This commit is contained in:
Fred Nicolson
2016-12-09 22:04:37 +00:00
parent d36a98b9b2
commit 9cbe2aa8e8
3 changed files with 41 additions and 20 deletions
+21 -6
View File
@@ -3,7 +3,9 @@
#include <TcpSocket.h>
#include <TcpListener.h>
#include <thread>
#include <atomic>
std::atomic<uint64_t> data_sent;
void server()
{
fr::TcpListener listener;
@@ -19,7 +21,7 @@ void server()
std::string message;
packet >> message;
std::cout << "Got: " << message << std::endl;
data_sent += 0x100000;
}
}
@@ -28,19 +30,32 @@ void client()
fr::TcpSocket socket;
socket.connect("127.0.0.1", "8081");
fr::Packet packet;
packet << "Hello, World!";
socket.send(packet);
std::string buffer(0x100000, 'c');
std::this_thread::sleep_for(std::chrono::milliseconds(100));
fr::Packet packet;
packet << buffer;
while(true)
{
socket.send(packet);
}
}
int main()
{
data_sent = 0;
std::thread t1(&server);
std::this_thread::sleep_for(std::chrono::milliseconds(100));
client();
auto start = std::chrono::system_clock::now();
std::thread t2(&client);
while(true)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
uint64_t mb_sent = data_sent / 0x100000;
std::cout << "Transfer speed: " << mb_sent / (uint64_t)std::chrono::duration<double>(std::chrono::system_clock::now() - start).count() << "MBps" << std::endl;
}
t1.join();
return 0;