plz help me to solve this socekt progm..urgent...


 
Thread Tools Search this Thread
Top Forums Programming plz help me to solve this socekt progm..urgent...
# 1  
Old 07-28-2010
Java plz help me to solve this socekt progm..urgent...

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.

Last edited by saiful_911; 07-28-2010 at 01:18 AM..
# 2  
Old 07-28-2010
gah, wanna quote your code a bit better next time ?
# 3  
Old 07-28-2010
plz help how can i do.plz plz...
# 4  
Old 07-28-2010
plz bankai help me..its urgent..plz read my requirement n help me...huhu...
# 5  
Old 07-28-2010
  1. Please take your time to check your posts for spelling errors. You might be time-pressed typing, but that way it takes us longer to understand what you're trying to tell us. This goes especially for "leetspeak".
  2. Your requirements don't go beyond any other random socket program. Homework?
  3. If that's not homework, search the net for "socket programming", fetch one of the (overly simplistic) examples, expand it a bit, and et voilą!
# 6  
Old 07-28-2010
any one help me to solve my home work.

This is home work and this is client server socket program. I have to use in C program code. What I have to do.

1. client connect to the server.
2. than 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.
3. than server, after receiving the username from client, it will send an acknowledgment message to the client.

4. client, after receiving the acknowledgment message from server, it will prompt a message that asks the user to enter the corresponding password.

5. This password will then be sent to the server. after receiving the password from client, will verify the received username and password. 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.


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

This is the scenario of the program. kindly please help me to solve this program.

Here I can connnect client and server but the rest of work I can not. My code is below.

Client code is

Code:
#include	"myfile.h"

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

	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 */
	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);
	}

	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);
}

Server code is

Code:
#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 */

	if (bind(listenfd, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0)
		exit(0);

	if( listen(listenfd, LISTENQ) <0)
		exit(0);

	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);
	}
}





thanks

Last edited by pludi; 07-28-2010 at 10:27 AM.. Reason: code tags, please...
# 7  
Old 07-28-2010
Homework goes here, if it follows the rules set forth here.

Thread closed.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

URGENT Reading a file and assessing the syntax shell script URGENT

I am trying to write a shell script which takes an input file as an arguement in the terminal e.g. bash shellscriptname.sh input.txt. I would like for the file to be read line by line each time checking if the .txt file contains certain words or letters(validating the syntax). If the line being... (1 Reply)
Discussion started by: Gurdza32
1 Replies

2. AIX

Need help..Urgent plz

Hi All, For listing large files i am using the following command find /XYZ/ -xdev -size +100000 |xargs ls -l |sort -nr -k 5..And my question is i am getting more number of files with this, so not able to copy those, how can I get those all in page by page , so that I can able to copy those... (4 Replies)
Discussion started by: adminaix55
4 Replies

3. Shell Programming and Scripting

error in shell script while returning values-- urgent issue plz help.

Hi, I have initailized a varaible EBID as typeset Long EBID=0 i am calculating value of EBID using certian formula as below: (( CURR_EBID= ($BANDINDEX << 27) | ($CURR_FREQ << 16) | ($CURR_CELLID << 4) | $CURR_SECTOR_VALUE )) return $CURR_EBID The output is as below: + (( CURR_EBID=... (6 Replies)
Discussion started by: kasanur
6 Replies

4. Shell Programming and Scripting

Clarify doubt ... plz Urgent

Hi friends, I am new to UNIX. I going to transfer files using SFTP. I am writing a script and using mget . If i am using mget * means, if all the files and their sub directories are transferred or not? If suppose , the local system dose not have the sub directory then what will... (1 Reply)
Discussion started by: punitha
1 Replies

5. UNIX for Dummies Questions & Answers

plz help me urgent....

i want shell script program for counting the no of times the given input word is occured in the given input file.i am unable to do this .i got some of output with awk but i need it completely with shell script program i am waiting for the solution (4 Replies)
Discussion started by: sankar_1209
4 Replies

6. Shell Programming and Scripting

help in writing awk script, plz urgent

I have a file like this I have to I have input file this , I want to give the out put in the below input file (NARAYANA 1 ENDING AT (100, 16383) ,NARAYANA 2 ENDING AT (100, 32766) ,NARAYANA 3 ENDING AT (100, 49149) ,NARAYANA 4 ENDING AT (100, 65535) ,NARAYANA 5... (8 Replies)
Discussion started by: LAKSHMI NARAYAN
8 Replies

7. Shell Programming and Scripting

plz solve this one : URGENT

Hi! How to use awk command and set command in a shell script? Suppose I have to fetch data from a file and change one data with another one.Say data is ABCD.Now I have to change C with X .How do I solve this one? (2 Replies)
Discussion started by: joyita bagchi
2 Replies

8. UNIX for Dummies Questions & Answers

find command - Urgent Plz.

Hi, In my current directory, i have the following files: x1.dat x2.dat.gz x3.dat I want to use the find command and display only files which has *.dat and NOT *.gz extension files. Please help me out. Thanks, Kris Kart. (2 Replies)
Discussion started by: Kris_Kart_101
2 Replies

9. UNIX for Dummies Questions & Answers

urgent plz

guys i have sun solaries 8 under intel .. i added a new D-LINK ethernet and i need to see if the computer define it or not .. so i need to make reconfiguraion .. what was the command ... for reconfiguration ??? thanks alot (3 Replies)
Discussion started by: tamemi
3 Replies

10. UNIX for Dummies Questions & Answers

plz Help How should I configure cc compiler output file plz help???

i.e configuration of C compiler :confused: (4 Replies)
Discussion started by: atiato
4 Replies
Login or Register to Ask a Question