generated from AfonsoCMSousa/CPP-Template
55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
#include <cstddef>
|
|
#include <cstdint>
|
|
#include <iostream>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "app.hpp" // for app_info struct
|
|
#include "file.hpp" // for parce_args
|
|
#include "net.hpp" // for socket operations
|
|
#include "server_structs.h"
|
|
|
|
using namespace std;
|
|
|
|
int main(int argc, char *argv[]) {
|
|
app_info app = parce_args(argc, argv);
|
|
api_packet packet;
|
|
|
|
Socket sock;
|
|
|
|
try {
|
|
// Connect socket to API
|
|
sock.connect_unix(app.app_api_socket_path.c_str(), app.app_port_out);
|
|
// Connect socket to Server
|
|
sock.connect_server(app.app_server_out_ip.c_str(), app.app_port_out, app.app_port_in);
|
|
|
|
// Right after connecting, send update rate request
|
|
char request[516] = {0};
|
|
request[0] = ACSP_REALTIMEPOS_INTERVAL;
|
|
request[1] = 120;
|
|
|
|
sock.send_server(request, sizeof(request));
|
|
cout << "[+] Connected to server!\n[!] Info: " << endl;
|
|
cout << " > API Socket Path: " << app.app_api_socket_path << endl;
|
|
cout << " > Server Out IP: " << app.app_server_out_ip << endl;
|
|
cout << " > App Port In: " << app.app_port_in << endl;
|
|
cout << " > App Port Out: " << app.app_port_out << endl;
|
|
|
|
} catch (const runtime_error &e) {
|
|
cerr << "Error: " << e.what() << endl;
|
|
return 1;
|
|
}
|
|
|
|
sock.receive_server();
|
|
char *buffer = sock.get_buffer();
|
|
cout << "Received " << sizeof(buffer) << " bytes from server." << endl;
|
|
cout << "Data: ";
|
|
for (size_t i = 0; i < sizeof(buffer); i++) {
|
|
printf("%02X ", static_cast<unsigned char>(buffer[i]));
|
|
}
|
|
cout << endl;
|
|
return 0;
|
|
}
|
|
|