summaryrefslogtreecommitdiff
path: root/C
diff options
context:
space:
mode:
Diffstat (limited to 'C')
-rw-r--r--C/HF/netplay.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/C/HF/netplay.c b/C/HF/netplay.c
new file mode 100644
index 0000000..3862a90
--- /dev/null
+++ b/C/HF/netplay.c
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <arpa/inet.h>
+
+char *advice[] = {
+ "Take the hard path\r\n",
+ "Don't please others\r\n",
+ "Ignore others opinions\r\n",
+ "Keep moving forward\r\n",
+};
+
+int
+main(void) {
+
+ int sock_d = socket(PF_INET, SOCK_STREAM, 0);
+
+ struct sockaddr_in name;
+ name.sin_family = PF_INET;
+ name.sin_port = (in_port_t)htons(30000);
+ name.sin_addr.s_addr = htonl(INADDR_ANY);
+
+ bind(sock_d, (struct sockaddr *)&name, sizeof(name));
+
+ listen(sock_d, 10);
+
+ puts("Waiting connection...\n");
+
+ while (1) {
+ struct sockaddr_storage client_addr;
+ unsigned int addr_size = sizeof(client_addr);
+ int client_sock = accept(sock_d, (struct sockaddr *)&client_addr,
+ &addr_size);
+
+ char *msg = advice[rand() % 4];
+
+ send(client_sock, msg, strlen(msg), 0);
+ close(client_sock);
+ }
+
+ return 0;
+}