4 #include <netinet/in.h>
7 #include <sys/socket.h>
14 #define SOCKET_PORT 32000
22 if ((
socket_fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
23 perror(
"Socket: socket");
27 bzero(&socket_server,
sizeof(socket_server));
28 socket_server.sin_family = AF_INET;
31 inet_aton(
"127.0.0.1", &socket_server.sin_addr);
34 if (bind(
socket_fd, (
struct sockaddr *)&socket_server,
sizeof(socket_server)) != 0) {
35 perror(
"Socket: bind");
43 socklen_t slen =
sizeof(socket_server);
44 return recvfrom(
socket_fd, buffer, len, MSG_DONTWAIT, (
struct sockaddr *)&socket_server, &slen);
49 socklen_t slen =
sizeof(socket_server);
50 sendto(
socket_fd, buffer, len, MSG_DONTWAIT, (
struct sockaddr *)&socket_server, slen);