CS计算机代考程序代写 //**************

//**************
//server
/*
#include
#include
#include
#include
*/

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include

#define SIZE sizeof(struct sockaddr_in)
int main() {

int sockfd;
char c;
/* the local server port */
struct sockaddr_in server = { AF_INET, 7000, INADDR_ANY };

/* the structure to put in process2’s address */
struct sockaddr_in client;
int client_len = SIZE;

/* set up the transport end point */
if ((sockfd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {
perror(“socket call failed”);
exit(1);
}
/*bind the local address to the end point */
if (bind(sockfd, (struct sockaddr *)&server, SIZE) == -1){
perror(“bind call failed”);
exit(1);
}
/* sit in a continual loop waiting for messages */
for (; ;){
/* recieves the message and stores the address of the client */
if (recvfrom(sockfd, &c, 1, 0, (struct sockaddr *)&client, &client_len) == -1){
perror(“server: receiving”);
continue;
}
c = toupper(c);
/*send the message back to where it comes from */
if (sendto(sockfd, &c, 1, 0, (struct sockaddr *)&client, client_len) == -1){
perror(“server: sending”);
continue;
}
}
}