Question: use the code included to do the following: 1.send array of integers to the server using the client program 2.receive the array and return the
use the code included to do the following:
1.send array of integers to the server using the client program
2.receive the array and return the sum,min,max and the average of the array as string message to the client
// client
#include#include #include #include #include #include int main(void){ int sockfd; int len; struct sockaddr_un address; int result; int amount=1; sockfd=socket(AF_UNIX,SOCK_STREAM,0); address.sun_family=AF_UNIX; strcpy(address.sun_path,"Server Socket"); len=sizeof(address); result=connect(sockfd,(struct sockaddr *)&address,len); if(result == -1){ perror("Clinet1"); exit(1); } write(sockfd,&amount,1); read(sockfd,&amount,1); printf("Char from server =%d ",amount); close(sockfd); exit(0); }
//server
#include#include #include #include #include #include int main(){ int server_sockfd,client_sockfd; int server_len,client_len; struct sockaddr_un server_address; struct sockaddr_un cleint_address; unlink("Server Socket"); server_sockfd=socket(AF_UNIX,SOCK_STREAM,0); server_address.sun_family=AF_UNIX; strcpy(server_address.sun_path,"Server Socket"); server_len=sizeof(server_address); bind(server_sockfd,(struct sockaddr *)&server_address,server_len); listen(server_sockfd,1); while(1){ int amount; printf("Server waiting "); client_len=sizeof(cleint_address); client_sockfd=accept(server_sockfd,(struct sockaddr *) &cleint_address,&client_len); read(client_sockfd,&amount,1); amount+=10; write(client_sockfd,&amount,1); close(client_sockfd); } }
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
