37 lines
873 B
C++

#include <ctype.h>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "server_structs.h"
#include "socket.h"
const int SERVER_OUT_PORT = 12000;
const int SERVER_IN_PORT = 11000;
const char *SERVER_IP = "127.0.0.1";
int main(void) {
printf("[+] Starting server...\n");
int n = connect_udp_socket(SERVER_IP, SERVER_OUT_PORT);
if (n < 0) {
fprintf(stderr, "[-] Failed to connect to UDP socket at %s:%d\n", SERVER_IP, SERVER_OUT_PORT);
return -1;
}
// TEST to see what server is sending:
char buffer[1024];
n = recvfrom(0, buffer, sizeof(buffer)-1, 0, NULL, NULL);
if (n < 0) {
perror("recvfrom failed");
return -1;
}
buffer[n] = '\0'; // Null-terminate the received message
printf("Received message: %s\n", buffer);
return 0;
}