I'm trying to write a simple program with two source files named client.c and server.c All it does is use sockets to connect a client to a server. The client types in a message and the server recieves the message echos it back to the client.

Here is client.c
Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdbool.h>
#include <sys/types.h>

#define MAXBUF 20
#define FALSE 0
#define TRUE 1

struct sockaddr_in sockme;
int s;

struct servent *pse;
char * transport = "tcp";
int portnum;
char *hostnum;

char bufout[MAXBUF+1];
char bufin[MAXBUF+1];
char *cp;
char c;

int result;
int n;

int main(int argc, char *argv[])
{

	if (argc == 3) {
		hostnum = argv[1];
		(void) sscanf(argv[2], "%d", &portnum);
	}
	else {
		(void) printf("usage: client <hostnum> <portnum>\n");
		exit(-1);
	}

	sockme.sin_family = AF_INET;

	if ((sockme.sin_addr.s_addr = inet_addr(hostnum)) == INADDR_NONE) {
		(void) printf("Invalid dotted decimal address\n");
		exit(-1);
	}

	sockme.sin_port = htons(portnum);
	
	if((s = socket(PF_INET, SOCK_STREAM, 0)) == 0)
	{
		/* if socket failed then display error and exit */
		perror("Create socket");
		exit(EXIT_FAILURE);
	}

	if ((result = connect (s, (struct sockaddr *) &sockme, sizeof(sockme)))) {
		perror("Connect failed\n");
		close (s);
		exit(-1);
	};

	(void) printf("Enter Message: \n");
	cp = bufout;
	while ((c = getchar()) != '\n') {
		*cp++ = c;
	}
	*cp = '\0';
	
	result = send (s, bufout, strlen(bufout), 0);
	
	if(result != strlen(bufout)){
		perror("send");
		exit(EXIT_FAILURE);
	}
	
	printf("Message Sent.\nWaiting for response.\n");
	
	do{
		n = read ( s, bufin, MAXBUF );
	}while(n != 0);
	
	(void) printf("Recieved: %s\n", bufin);
	result = close(s);

	return 0;
}
Here is server.c

Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <stdbool.h>
#include <sys/types.h>

#define MAXBUF 20
#define FALSE 0
#define TRUE 1

struct sockaddr_in sockme, newsockme;
int s, childs;
char *hostnum;

int type;
int portnum;

int result;

char bufout[MAXBUF+1];
char bufin[MAXBUF+1];
char *cp;
char c;

int n;


int main(int argc, char *argv[])
{

	if (argc == 2) {
		(void) sscanf(argv[1], "%d", &portnum);
	}
	else {
		(void) printf("usage: server <portnum>\n");
		exit(-1);
	}
	
	sockme.sin_family = AF_INET;
	sockme.sin_addr.s_addr = INADDR_ANY;
	sockme.sin_port = htons(portnum);

	/* the following socket is used to listen for incoming connection
	 * requests by any clients
	 */
	
	if((s = socket(PF_INET, SOCK_STREAM, 0)) == 0)
	{
		/* if socket failed then display error and exit */
		perror("Create socket");
		exit(EXIT_FAILURE);
	}


	result = bind(s, (struct sockaddr *) &sockme, sizeof(sockme));
	
	if(result < 0){
		perror("bind");
		exit(-1);
	}
		
	result = listen(s, 5);
	
	if(result < 0){
		perror("listen");
		exit(-1);
	}

	while (1) {
		socklen_t alen = sizeof(newsockme);
		
		childs = accept(s, (struct sockaddr *) &newsockme, &alen);
		if(childs < 0){
			perror("accept");
			exit(-1);
		}
		printf("Handling client %s\n", inet_ntoa(newsockme.sin_addr));
		
		
		do{
			n = read ( s, bufin, MAXBUF );
		}while(n != 0);
		
		bufin[MAXBUF] = '\0';
	
		(void) printf("Message recieved: %s\n", bufin);
		(void) printf("Sending: %s\n", bufin);
		
		result = send (childs, bufin, strlen(bufin), 0);
		result = close(childs);
	}

	return 0;
}
I run server.c with the:
./server 5601

and client.c with:
./client 127.0.0.1 5601

I get the following output from server.c:
Handling client 127.0.0.1

and from client.c:
Enter Message:
Hello World
Message Sent.
Waiting For Response.

For some reason the do while loop in server.c never exits. Can anyone spot my mistake and point me in the right direction?

Thank you.