summaryrefslogtreecommitdiff
path: root/server/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/main.c')
-rw-r--r--server/main.c42
1 files changed, 41 insertions, 1 deletions
diff --git a/server/main.c b/server/main.c
index 237c8ce..789d392 100644
--- a/server/main.c
+++ b/server/main.c
@@ -1 +1,41 @@
-int main() {}
+#include <stdio.h>
+#include <stdlib.h>
+#include <err.h>
+#include <sys/socket.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <time.h>
+
+int main() {
+ int fd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ if (fd == -1)
+ err(EXIT_FAILURE, "socket failed");
+
+ struct sockaddr_in address;
+ address.sin_family = AF_INET;
+ address.sin_port = htons(8080);
+ address.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
+
+ if (bind(fd, (struct sockaddr *)&address, sizeof(address)) == -1) {
+ close(fd);
+ err(EXIT_FAILURE, "bind failed");
+ }
+
+ time_t startTime = time(NULL);
+
+ while (time(NULL) < startTime + 60) {
+ struct sockaddr connection;
+ socklen_t connectionLen = sizeof(connection);
+ char buff[64];
+
+ int size = recvfrom(fd, buff, sizeof(buff), MSG_DONTWAIT,
+ (struct sockaddr *)&connection, &connectionLen);
+
+ if (size != -1)
+ printf("got a message\n");
+ }
+
+ close(fd);
+ return 0;
+}