VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1
VND Openxmlformats-Officedocument Wordprocessingml Document&rendition 1
ALOGRITHM:
1. The concurrent client server model is a model which communicates with the client
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
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include<netinet/in.h>
#include<arpa/inet.h>
int sockfd,rval,pid;
char buff1[20],buff2[20];
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)
len=sizeof(client);
if(rval==-1)
perror("\n RECV_ERR\n");
exit(1);
else
rval=sendto(sockfd,buff1,sizeof(buff1),0,(struct sockaddr*)&client,sizeof(client
));
if(rval!=-1)
else
perror("\n SEND_ERR\n");
exit(1);
else
else
perror("\n BIND_ERR\n");
exit(1);
}
Server Output:
Childprocess Executing
parent process
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include<netinet/in.h>
#include <arpa/inet.h>
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);
scanf("%s", buff1);
er));
if(rval!=-1)
}
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
Client Output:
parent process ID is 1
Received Message is hi