aboutsummaryrefslogtreecommitdiff
path: root/src/client.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.c')
-rw-r--r--src/client.c48
1 files changed, 0 insertions, 48 deletions
diff --git a/src/client.c b/src/client.c
deleted file mode 100644
index 0b9cbfe..0000000
--- a/src/client.c
+++ /dev/null
@@ -1,48 +0,0 @@
-#include <sys/socket.h>
-#include <arpa/inet.h>
-#include <strings.h>
-#include <sys/types.h>
-#include <unistd.h>
-#include <stdbool.h>
-#include <stdio.h>
-
-#include "util.h"
-
-int
-main()
-{
- int sockfd = socket(AF_INET, SOCK_STREAM, 0);
- if (sockfd == -1)
- panic("socket creation error");
-
- struct sockaddr_in serv_addr;
- bzero(&serv_addr, sizeof(serv_addr));
- serv_addr.sin_family = AF_INET;
- serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
- serv_addr.sin_port = htons(8888);
-
- if (connect(sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr)) == -1)
- panic("socket connect error");
-
- for (;;) {
- char buf[1024];
- bzero(&buf, sizeof(buf));
- scanf("%s", buf);
- ssize_t n_write_bytes = write(sockfd, buf, sizeof(buf));
- if (n_write_bytes == -1) {
- printf("socket already disconnected, cannot write any more!\n");
- break;
- }
-
- ssize_t n_read_bytes = read(sockfd, buf, sizeof(buf));
- if (n_read_bytes > 0) {
- printf("message from server: %s\n", buf);
- } else if (n_read_bytes == 0) {
- printf("server socket disconnected!\n");
- break;
- } else if (n_read_bytes == -1) {
- close(sockfd);
- panic("socket read error");
- }
- }
-}