client now sending to server
authorDylan Lloyd <dylan@dylansserver.com>
Sun, 29 Jan 2012 18:51:17 +0000 (13:51 -0500)
committerDylan Lloyd <dylan@dylansserver.com>
Sun, 29 Jan 2012 18:51:17 +0000 (13:51 -0500)
client.c
makefile [new file with mode: 0644]
server.c

index b494807..57078dc 100644 (file)
--- a/client.c
+++ b/client.c
@@ -72,20 +72,10 @@ int main(int argc, char *argv[])
                return 2;
        }
 
-       inet_ntop(p->ai_family, get_in_addr((struct sockaddr *)p->ai_addr),
-                       s, sizeof s);
-       printf("client: connecting to %s\n", s);
+    if (send(sockfd, "Hello, world!", 13, 0) == -1)
+        perror("send");
 
-       freeaddrinfo(servinfo); // all done with this structure
-
-       if ((numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) {
-           perror("recv");
-           exit(1);
-       }
-
-       buf[numbytes] = '\0';
-
-       printf("client: received '%s'\n",buf);
+    printf("connected\n");
 
        close(sockfd);
 
diff --git a/makefile b/makefile
new file mode 100644 (file)
index 0000000..6cf89b3
--- /dev/null
+++ b/makefile
@@ -0,0 +1,3 @@
+all: server.c client.c
+server: server.c
+client: client.c
index 74cf914..1da2bcd 100644 (file)
--- a/server.c
+++ b/server.c
@@ -115,8 +115,13 @@ int main(void)
 
                if (!fork()) { // this is the child process
                        close(sockfd); // child doesn't need the listener
-                       if (send(new_fd, "Hello, world!", 13, 0) == -1)
-                               perror("send");
+            char buf[100];
+            if (recv(new_fd, buf, 99, 0) == -1) {
+                perror("recv");
+                exit(1);
+            }
+            buf[100] = '\0';
+            printf("server: recieved '%s'\n", buf);
                        close(new_fd);
                        exit(0);
                }