generated from AfonsoCMSousa/CPP-Template
fix: fixed more net.cpp problems
This commit is contained in:
parent
9da9cd3c13
commit
159a93317e
BIN
PlayerTracker
BIN
PlayerTracker
Binary file not shown.
@ -23,7 +23,7 @@ void Socket::connect_server(const char *ip, uint16_t port) {
|
|||||||
|
|
||||||
// Connect to existing UNIX domain socket (e.g., /tmp/socket_path)
|
// Connect to existing UNIX domain socket (e.g., /tmp/socket_path)
|
||||||
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_DGRAM, 0);
|
sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||||
if (sock < 0) {
|
if (sock < 0) {
|
||||||
throw std::runtime_error("Failed to create UNIX socket");
|
throw std::runtime_error("Failed to create UNIX socket");
|
||||||
}
|
}
|
||||||
@ -32,7 +32,7 @@ void Socket::connect_unix(const char *ip, uint16_t port) {
|
|||||||
this->server_addr_unix.sun_family = AF_UNIX;
|
this->server_addr_unix.sun_family = AF_UNIX;
|
||||||
strncpy(this->server_addr_unix.sun_path, ip, sizeof(this->server_addr_unix.sun_path) - 1);
|
strncpy(this->server_addr_unix.sun_path, ip, sizeof(this->server_addr_unix.sun_path) - 1);
|
||||||
|
|
||||||
if (connect(sock, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 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");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -45,10 +45,10 @@ void Socket::send_server() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Socket::send_unix() {
|
void Socket::send_unix() {
|
||||||
ssize_t sent_bytes = sendto(sock, &packet_data, sizeof(packet_data), 0, (struct sockaddr *)&server_addr_unix, sizeof(server_addr_unix));
|
ssize_t sent_bytes = send(sock, &packet_data, sizeof(packet_data), 0);
|
||||||
if (sent_bytes < 0) {
|
if (sent_bytes < 0) {
|
||||||
throw runtime_error("Failed to send data to UNIX socket");
|
throw runtime_error("Failed to send data to UNIX socket");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::send_server(const api_packet &data) {
|
void Socket::send_server(const api_packet &data) {
|
||||||
@ -59,10 +59,10 @@ void Socket::send_server(const api_packet &data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Socket::send_unix(const api_packet &data) {
|
void Socket::send_unix(const api_packet &data) {
|
||||||
ssize_t sent_bytes = sendto(sock, &data, sizeof(data), 0, (struct sockaddr *)&server_addr_unix, sizeof(server_addr_unix));
|
ssize_t sent_bytes = send(sock, &data, sizeof(data), 0);
|
||||||
if (sent_bytes < 0) {
|
if (sent_bytes < 0) {
|
||||||
throw runtime_error("Failed to send data to UNIX socket");
|
throw runtime_error("Failed to send data to UNIX socket");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Socket::set_packet(const api_packet &data) {
|
void Socket::set_packet(const api_packet &data) {
|
||||||
@ -81,4 +81,3 @@ api_packet Socket::create_packet(uint8_t tracker_id) {
|
|||||||
api_packet Socket::get_packet() {
|
api_packet Socket::get_packet() {
|
||||||
return packet_data;
|
return packet_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user