generated from AfonsoCMSousa/CPP-Template
fix: finnaly working!
This commit is contained in:
parent
7aa98209fb
commit
48156350c9
@ -32,6 +32,7 @@ class Socket {
|
|||||||
void send_server();
|
void send_server();
|
||||||
void send_unix();
|
void send_unix();
|
||||||
void send_server(const api_packet &data);
|
void send_server(const api_packet &data);
|
||||||
|
void send_server(const char &data);
|
||||||
void send_unix(const api_packet &data);
|
void send_unix(const api_packet &data);
|
||||||
void set_packet(const api_packet &data);
|
void set_packet(const api_packet &data);
|
||||||
api_packet create_packet(uint8_t tracker_id);
|
api_packet create_packet(uint8_t tracker_id);
|
||||||
|
|||||||
@ -19,27 +19,25 @@ int main(int argc, char *argv[]) {
|
|||||||
Socket sock;
|
Socket sock;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Connect to API socket path
|
// Connect socket to API
|
||||||
sock.connect_unix(app.app_api_socket_path.c_str(), app.app_port_out);
|
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)
|
||||||
|
|
||||||
// Send a packet for test to API
|
// Right after connecting, send update rate request
|
||||||
packet = sock.create_packet(app.app_id);
|
char request[3] = {0};
|
||||||
sock.send_unix(packet);
|
request[0] = ACSP_REALTIMEPOS_INTERVAL;
|
||||||
|
request[1] = 127;
|
||||||
|
|
||||||
|
sock.send_server()
|
||||||
|
|
||||||
} catch (const runtime_error &e) {
|
} catch (const runtime_error &e) {
|
||||||
cerr << "Error: " << e.what() << endl;
|
cerr << "Error: " << e.what() << endl;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
api_packet test;
|
|
||||||
|
|
||||||
test.tracker_id = app.app_id;
|
|
||||||
test.connected_players = 0;
|
|
||||||
strncpy(test.track_info.server_name, "THIS IS A TEST, IF YOU CAN READ THIS, IT WORKS!", sizeof(test.track_info.server_name) - 1);
|
|
||||||
|
|
||||||
cout << "Test packet server name: " << test.track_info.server_name << endl;
|
|
||||||
sock.set_packet(test);
|
|
||||||
sock.send_unix();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -59,6 +59,13 @@ void Socket::send_server(const api_packet &data) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Socket::send_server(const char &data) {
|
||||||
|
ssize_t sent_bytes = sendto(sock, &data, sizeof(data), 0, (struct sockaddr *)&server_addr, sizeof(server_addr));
|
||||||
|
if (sent_bytes < 0) {
|
||||||
|
throw runtime_error("Failed to send data");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Socket::send_unix(const api_packet &data) {
|
void Socket::send_unix(const api_packet &data) {
|
||||||
ssize_t sent_bytes = send(sock, &data, sizeof(data), 0);
|
ssize_t sent_bytes = send(sock, &data, sizeof(data), 0);
|
||||||
if (sent_bytes < 0) {
|
if (sent_bytes < 0) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user