0% found this document useful (0 votes)
17 views

VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1

Uploaded by

sanjayyalla4661
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1

Uploaded by

sanjayyalla4661
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

3. Implementation of Connectionless Iterative time service (UDP).

ALOGRITHM:

1. The concurrent client server model is a model which communicates with the client

in the parallel method of communication .

2. Not like in the normal or iterative client server model the server in the concurrent

client server model communicates with all the clients at the same time using the

ability of “fork()”.

3. That is the fork() is a command that develops duplicate process or a parent and

child process.

4. Like wise the server is like a parent process which creates a child process

separately for all the incoming clients .So that the communication process is

completed as in normal or iterative client server process.

5. This is the main functionality of concurrent client and server model.


(a) Concurrent Connection less Server

#include <stdio.h>

#include <sys/types.h>

#include <sys/socket.h>

#include<netinet/in.h>

#include<arpa/inet.h>

main(int argc, char *argv[])

int sockfd,rval,pid;

char buff1[20],buff2[20];

struct sockaddr_in server, client;

int len;

sockfd=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);

if(sockfd==-1)

server.sin_family=AF_INET;

server.sin_addr.s_addr=inet_addr("192.168.0.5");

server.sin_port=htons(3221);
rval=bind(sockfd,(struct sockaddr*)&server,sizeof(server));

if(rval!=-1)

pid=fork();

if(pid==0)

printf("\n Childprocess Executing \n");

printf("\n child process ID Is:%d\n", getpid());

len=sizeof(client);

rval=recvfrom(sockfd, buff1,sizeof(buff1),0,(struct sockaddr*)&client,&len);

if(rval==-1)

perror("\n RECV_ERR\n");

exit(1);

else

{printf("\n Received Message Is:%s\n",buff1);

rval=sendto(sockfd,buff1,sizeof(buff1),0,(struct sockaddr*)&client,sizeof(client

));
if(rval!=-1)

printf("\n Message sent successfully \n");

else

perror("\n SEND_ERR\n");

exit(1);

else

printf("\n parent process\n");

printf("parent process ID is %d\n", getppid());

else

perror("\n BIND_ERR\n");

exit(1);

}
Server Output:

[staff@cc5 cnlab]$ cc coservercl.c

[staff@cc5 cnlab]$ ./a.out 192.168.0.5

Childprocess Executing

child process ID Is:3217

parent process

parent process ID is 2341

Received Message is: hi

(b) Concurrent Connection less Client

#include <stdio.h>

#include <sys/types.h>

#include <sys/socket.h>

#include<netinet/in.h>

#include <arpa/inet.h>

main(int argc, char *argv[])

int sockfd, rval;


char buff1[20],buff2[20];

struct sockaddr_in server, client;

int len;

sockfd=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);

if(sockfd==-1)

perror("\n SOCK_ERR\n");

exit(1);

server.sin_family=AF_INET;

server.sin_addr.s_addr=inet_addr("192.168.0.5");

server.sin_port=htons(3221);

printf("\n enter a message \n");

scanf("%s", buff1);

rval=sendto(sockfd, buff1, sizeof(buff1),0,(struct sockaddr*)&server,sizeof(serv

er));

if(rval!=-1)

printf("\nmessage sent successfully\n");

}
else

perror("\n SEND_ERR\n");

exit(1);

len=sizeof(server);

rval=recvfrom(sockfd,buff1,sizeof(buff1),0,(struct sockaddr*)&server,&len);

if(rval==-1)

perror("\nRECV_ERR\n");

exit(1);

else

printf("\n Received Message is %s\n", buff1);

Client Output:

[staff@cc5 cnlab]$ cc coclientcl.c

[staff@cc5 cnlab]$. /a.out 192.168.0.5


enter a message hi

message sent successfully

Message sent successfully

parent process ID is 1

Received Message is hi

You might also like