saiful_911 0 Newbie Poster

plz help me to solve the below problem.i have done some code.

MY client and server need to achieve the following requirements:

1.1. program for client needs to take two arguments that specify the name of server and the port that it is trying to connect to. Your program for server needs to take an argument that specifies the port that it is listening to.

2.2. server will start first and keep listening to the specified port. Your client will connect to the port that your server is listening to, and a socket between your client and server is constructed.


4.3. client will first prompt a welcome message that asks the user to enter a username using the keyboard. This username will then be sent to the server. Then, your server, after receiving the username from your client, will send an acknowledgment message to the client.

6.4. client, after receiving the acknowledgment message from your server, will prompt a message that asks the user to enter the corresponding password. This password will then be sent to the server. Then, your server, after receiving the password from your client, will verify the received pair of username and password against the list of legitimate pairs. If the result is positive, the server will send a success message to the client. If the result is negative, the server will send a failure message to the client.

8.5. client, after receiving the result message, will print out the result and close the socket. Your server will close the socket following the client, and keep listening for the next client request.

this my code:

daytimetcpcli.c

-------------------------------------
#include	"myfile.h"

int
main(int argc, char **argv)
{
	int					sockfd, n;
	char				recvline[MAXLINE + 1];
	struct sockaddr_in	servaddr;
	
	int sock;

            char name[5];
            unsigned int echolen;
            int received = 0;


	if (argc != 2) {
		perror("usage: a.out <IPaddress>");
		exit (1);
	}


	if ( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
		perror("socket error");
		exit(1);
	}

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family = AF_INET;
	servaddr.sin_port   = htons(SERV_PORT);	/* daytime server */
	
	//char name;
	printf ("Welcome to the server \n");
	printf (" Enter user name: \n");
	scanf ("%c", &name);

	if (inet_pton(AF_INET, argv[1], &servaddr.sin_addr) <= 0) {
		printf("inet_pton error for %s", argv[1]);
		exit(0);
	}

	if (connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) {
		perror("connect error");
		exit(1);
	int sock;
	name = strlen(argv[5]);
            if (send(sock, argv[5], name, 0) != name) {
              Die("Mismatch in number of sent bytes");
		}	
	
	//char name1="Adam";
	
	}
	
	
	while ( (n = read(sockfd, recvline, MAXLINE)) > 0) {
		recvline[n] = 0;	/* null terminate */
		if (fputs(recvline, stdout) == EOF) {
			perror("fputs error");
			exit(1);
		}
	}
	if (n < 0) {
		perror("read error");
	}

	exit(0);
}

daytimesrv.c
--------------------

#include	"myfile.h"
#include	<time.h>

int
main(int argc, char **argv)
{
	int					listenfd, connfd;
	struct sockaddr_in	servaddr;
	char				buff[MAXLINE];
	time_t				ticks;

	listenfd = socket(AF_INET, SOCK_STREAM, 0);
	if (listenfd < 0)
		exit(0);

	bzero(&servaddr, sizeof(servaddr));
	servaddr.sin_family      = AF_INET;
	servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
	servaddr.sin_port        = htons(SERV_PORT);	/* daytime server */
	printf ("Server is connected \n");

	if (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0)
		exit(0);
	//printf("Enter User Name: \n");
	if( listen(listenfd, LISTENQ) <0)
		exit(0);
	
	
	//int i;
	
	//char name1="Adam";
	
	



	for ( ;; ) {
			
		connfd = accept(listenfd, (struct sockaddr *) NULL, NULL);
		
		if (connfd<0) {
			perror("connection failure");
			continue;
		}
		
		


	ticks = time(NULL);
        snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
        if( write(connfd, buff, strlen(buff)) < 0) {
		perror("error in writing");
	}

	close(connfd);
	}

//}

plz help me asap n reply.its urgent.:S

plz help me to solve above problem.its urgent.