Question: Client Starter Code: /* Simple udp client */ #include #include #include #include #include #include #define SERVER 129.120.151.95 #define BUFLEN 512 //Max length of buffer #define

 Client Starter Code: /* Simple udp client */ #include #include #include

Client Starter Code:

/* Simple udp client */ #include #include #include #include #include #include #define SERVER "129.120.151.95" #define BUFLEN 512 //Max length of buffer #define PORT 6700 //The port on which to send data void die(char *s) { perror(s); exit(1); } int main(void) { struct sockaddr_in si_other; int sockfd, i=0, slen=sizeof(si_other), portno; char buf[BUFLEN]; char message[BUFLEN]; if ( (sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } memset((char *) &si_other, 0, sizeof(si_other)); si_other.sin_family = AF_INET; si_other.sin_port = htons(PORT); if (inet_aton(SERVER , &si_other.sin_addr) == 0) { fprintf(stderr, "inet_aton() failed "); exit(1); } while(1) { //Clear the message buffer and accept the message to be sent printf("Enter message: "); bzero(message, sizeof(message)); do { message[i] = getchar(); i++; } while (message[i-1] != ' '); i = 0; //send the message if (sendto(sockfd, message, strlen(message), 0, (struct sockaddr *) &si_other, slen) == -1) { die("sendto()"); } //receive a reply and print it //clear the buffer by filling null, it might have previously received data bzero(buf, sizeof(buf)); //try to receive some data, this is a blocking call if (recvfrom(sockfd, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen) == -1) { die("recvfrom()"); } printf("Received message from the server: "); printf("%s ", buf); } close(sockfd); return 0; }

Server Starter Code:

/* Simple udp server */ #include #include #include #include #include #include #define BUFLEN 512 //Max length of buffer #define PORT 6700 //The port on which to listen for incoming data void die(char *s) { perror(s); exit(1); } int main(void) { struct sockaddr_in si_me, si_other; int sockfd, i, slen = sizeof(si_other) , recv_len; char buf[BUFLEN]; //create a UDP socket if ((sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } // zero out the structure memset((char *) &si_me, 0, sizeof(si_me)); si_me.sin_family = AF_INET; si_me.sin_port = htons(PORT); si_me.sin_addr.s_addr = htonl(INADDR_ANY); //bind socket to port if(bind(sockfd, (struct sockaddr*)&si_me, sizeof(si_me) ) == -1) { die("bind"); } //keep listening for data while(1) { printf("Waiting for data... "); fflush(stdout); bzero (buf, BUFLEN); //try to receive some data, this is a blocking call if ((recv_len = recvfrom(sockfd, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &slen)) == -1) { die("recvfrom()"); } //print details of the client/peer and the data received printf("Received packet from %s:%d ", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port)); printf("Received Data: %s " , buf); /ow reply the client with the same data if (sendto(sockfd, buf, recv_len, 0, (struct sockaddr*) &si_other, slen) == -1) { die("sendto()"); } bzero(buf, sizeof(buf)); } close(sockfd); return 0; }

1. Create a C-based server that can run on cse02.cse.unt.edu and accepts single client's request using UDP socket 2. Create a C-based client that runs on cse03.cse.unt.edu and connects to the server 3. On the client side, create a UDP segment (as shown in Figure 1) using C structure that has the following fields: o 16-bit source port [Type: unsigned short int] o 16-bit destination port [Type: unsigned short int] o 16-bit length [Type: unsigned short int] o 16-bit checksum (Type: unsigned short int, computed after the header and payload is populated] o 256-byte payload (data) [Type: char] 4. Find the source port, destination port, and length and populate the corresponding fields of the UDP segment 5. Read the input (input.txt) text file (256 bytes) and populate the contents of the text file as the payload of the UDP segment 6. Compute the 16-bit checksum for the entire UDP segment and populate the checksum field and transmit the segment 7. Print on the client console and write to a client.log file the values of source port, destination port, length, checksum, and payload of the segment that is transmitted 8. The server will receive the UDP segment from the client and compute the checksum of the received UDP segment. 1. Create a C-based server that can run on cse02.cse.unt.edu and accepts single client's request using UDP socket 2. Create a C-based client that runs on cse03.cse.unt.edu and connects to the server 3. On the client side, create a UDP segment (as shown in Figure 1) using C structure that has the following fields: o 16-bit source port [Type: unsigned short int] o 16-bit destination port [Type: unsigned short int] o 16-bit length [Type: unsigned short int] o 16-bit checksum (Type: unsigned short int, computed after the header and payload is populated] o 256-byte payload (data) [Type: char] 4. Find the source port, destination port, and length and populate the corresponding fields of the UDP segment 5. Read the input (input.txt) text file (256 bytes) and populate the contents of the text file as the payload of the UDP segment 6. Compute the 16-bit checksum for the entire UDP segment and populate the checksum field and transmit the segment 7. Print on the client console and write to a client.log file the values of source port, destination port, length, checksum, and payload of the segment that is transmitted 8. The server will receive the UDP segment from the client and compute the checksum of the received UDP segment

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!