forked from Erfaniaa/fix-protocol
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaintestclient.cpp
More file actions
58 lines (48 loc) · 2.1 KB
/
Copy pathmaintestclient.cpp
File metadata and controls
58 lines (48 loc) · 2.1 KB
1
2
3
4
5
6
7
8
9
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
#include <thread>
#include <chrono>
#include "../include/fixedstring.h"
#include "../include/messagefactory.h"
#include "../include/clientconnection.h"
#include "../include/logger.h"
void receive_and_log_message(ClientConnection& client_connection, FixedString& received_fixed_string) {
received_fixed_string = client_connection.receive_message();
if (received_fixed_string.size() == 0)
return;
Logger().log_info(const_cast<char*>("Message received"));
Logger().log_info(received_fixed_string.c_str());
}
int main() {
ClientConnection client_connection;
FixedString received_fixed_string;
client_connection.open_connection();
Message message = MessageFactory().create_logon();
FixedString serialized_message = message.serialize();
client_connection.send_message(serialized_message);
Logger().log_info(const_cast<char*>("Message sent"));
Logger().log_info(serialized_message.c_str());
for (int i = 1; i <= 5000; i++) {
std::this_thread::sleep_for(std::chrono::milliseconds(50));
message = MessageFactory().create_heartbeat();
message.add_field(constants::MSG_SEQ_NUM, FixedString(i));
message.add_field(constants::CHECKSUM, message.get_checksum());
serialized_message = message.serialize();
client_connection.send_message(serialized_message);
Logger().log_info(const_cast<char*>("Message sent"));
Logger().log_info(serialized_message.c_str());
std::this_thread::sleep_for(std::chrono::milliseconds(50));
i++;
message = MessageFactory().create_resend_request(i, i);
message.add_field(constants::MSG_SEQ_NUM, FixedString(i));
message.add_field(constants::CHECKSUM, message.get_checksum());
serialized_message = message.serialize();
client_connection.send_message(serialized_message);
Logger().log_info(const_cast<char*>("Message sent"));
Logger().log_info(serialized_message.c_str());
receive_and_log_message(client_connection, received_fixed_string);
}
serialized_message = MessageFactory().create_logout().serialize();
client_connection.send_message(serialized_message);
Logger().log_info(const_cast<char*>("Message sent"));
Logger().log_info(serialized_message.c_str());
return 0;
}