39 lines
803 B
C

#ifndef SOCKET_H
#define SOCKET_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#pragma comment(lib, "ws2_32.lib") // link Winsock
#else
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
#endif
// =========================
// UDP SOCKET FUCNTIONS
// =========================
// Server hosts a UDP socket at 127.0.0.1:12000
// Client sends a message to the server at 11000
int connect_udp_socket(const char *ip, uint16_t port);
int bind_udp_socket(int sockfd, const char *ip, uint16_t port);
ssize_t send_udp_message(int sockfd, const char *message, const char *dest_ip,
uint16_t dest_port);
#ifdef __cplusplus
}
#endif
#endif // SOCKET_H