generated from AfonsoCMSousa/CPP-Template
fix: finnaly working!
This commit is contained in:
parent
dc071a2fc9
commit
7aa98209fb
@ -16,13 +16,14 @@ int main(int argc, char *argv[]) {
|
|||||||
app_info app = parce_args(argc, argv);
|
app_info app = parce_args(argc, argv);
|
||||||
api_packet packet;
|
api_packet packet;
|
||||||
|
|
||||||
try {
|
|
||||||
Socket sock;
|
Socket sock;
|
||||||
|
|
||||||
|
try {
|
||||||
// Connect to API socket path
|
// Connect to API socket path
|
||||||
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);
|
||||||
|
|
||||||
// Send a packet for test to API
|
// Send a packet for test to API
|
||||||
packet = sock.create_packet(app.app_id); // tracker_id = 1
|
packet = sock.create_packet(app.app_id);
|
||||||
sock.send_unix(packet);
|
sock.send_unix(packet);
|
||||||
|
|
||||||
} catch (const runtime_error &e) {
|
} catch (const runtime_error &e) {
|
||||||
@ -30,7 +31,15 @@ int main(int argc, char *argv[]) {
|
|||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -25,7 +25,6 @@ void Socket::connect_server(const char *ip, uint16_t port) {
|
|||||||
void Socket::connect_unix(const char *ip, uint16_t port) {
|
void Socket::connect_unix(const char *ip, uint16_t port) {
|
||||||
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
perror("socket() Failed");
|
|
||||||
throw std::runtime_error("Failed to create UNIX socket");
|
throw std::runtime_error("Failed to create UNIX socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -37,8 +36,6 @@ void Socket::connect_unix(const char *ip, uint16_t port) {
|
|||||||
if (connect(sock, (struct sockaddr *)&server_addr_unix, sizeof(server_addr_unix)) < 0) {
|
if (connect(sock, (struct sockaddr *)&server_addr_unix, sizeof(server_addr_unix)) < 0) {
|
||||||
throw std::runtime_error("Failed to connect to UNIX socket");
|
throw std::runtime_error("Failed to connect to UNIX socket");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("Connected to UNIX socket at %s\n", ip);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::send_server() {
|
void Socket::send_server() {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user