Computer network homework

Anonymous
timer Asked: May 2nd, 2017

Question description

Modify p3client.c and p3server.c To test this homework, you need p3client.c, forwarder.c and p3server.c

• Establish a connection between p3client and p3server on UDP. (50 Points)

– p3client sends a digit or letter to forwarder, and then forwarder sends the same to p3server. For this homework, write C code for an UDP connection between p3client and p3server.

• Once p3server receives the digit or letter, p3server sends a message to p3clinet using UDP. (50 Points)

– p3server decides whether the received message is a digit or not. If it is not a digit, send “This is not a digit” to p3client on UDP. Otherwise, send the digit to p3client on UDP.

Note:

• You have to modify only two files posted -- p3client.c and p3server.c.

• For testing, Use forwarder.c modified.

• Submission: your p3client.c and p3server.c


I have uploaded a word file for you that will help you and it has some example, and the p3client.c and p3server.c files.

// forwarder.c by Dr. Junwan Kim // This program MUST be used for only csci315 at UDC // #include #include #include #include #include #include #include #include #define PORTNUM1 2300 #define PORTNUM2 2400 #define MAXRCVLEN 500 int main(int argc, char *argv[]) { char* msg = "HI CSCI315 from Inter-server\n"; char buffer[MAXRCVLEN + 1]; int len, consocket; struct sockaddr_in dest; struct sockaddr_in serv; struct sockaddr_in client; int server_socket; int client_socket; // For server socklen_t socksize = sizeof(struct sockaddr_in); memset(&serv, 0, sizeof(serv)); serv.sin_family = AF_INET; serv.sin_addr.s_addr = htonl(INADDR_ANY); serv.sin_port = htons(PORTNUM1); server_socket = socket(AF_INET, SOCK_STREAM, 0); bind(server_socket, (struct sockaddr *)&serv, sizeof(struct sockaddr)); // // // // Write your code for for client here socket, connect, and recv here printf("As a client, I Received %s \n", buffer); memset(buffer, 0, strlen(buffer)); printf("Server starts...\n"); do{ listen(server_socket, 1); consocket = accept(server_socket, (struct sockaddr *)&dest, &socksize); send(consocket, msg, strlen(msg), 0); while(len=recv(consocket, buffer, MAXRCVLEN, 0)>0){ printf("Received: %s ", buffer); // As a client, send "buffer" here if(strncmp(buffer, "exit", 4) == 0){ break; } memset(buffer, 0, strlen(buffer)); } printf("Goodbye !\n"); close(consocket); }while(consocket); close(client_socket); close(server_socket); return EXIT_SUCCESS; }
// //Client.c by Dr. Junwhan Kim //This MUST be used for only CSCI315 at UDC // #include #include #include #include #include #include #include #include #define MAXRCVLEN 500 #define PORTNUM 2300 int main(int argc, char *argv[]) { char buffer[MAXRCVLEN + 1]; // for receiving int len, mysocket; struct sockaddr_in dest; char msg[MAXRCVLEN + 1]; // for sending mysocket = socket(AF_INET, SOCK_STREAM, 0); memset(&dest, 0, sizeof(dest)); dest.sin_family = AF_INET; dest.sin_addr.s_addr = htonl(INADDR_LOOPBACK); dest.sin_port = htons(PORTNUM); connect(mysocket, (struct sockaddr *)&dest, sizeof(struct sockaddr)); len = recv(mysocket, buffer, MAXRCVLEN, 0); if(len < 0){ perror("Reciver failed"); close(mysocket); return EXIT_FAILURE; } else{ buffer[len] = '\0'; printf("I Received %s \n", buffer); } while(1){ printf("Enter a character "); fgets(msg, sizeof(msg), stdin); if(strncmp(msg, "exit", 4) == 0) break; if(send(mysocket, msg, strlen(msg), 0) < 0){ perror("Send failed"); close(mysocket); return EXIT_FAILURE; } memset(msg, 0, strlen(msg)); } close(mysocket); return EXIT_SUCCESS; }
// Server.c by Dr. Junwan Kim // This program MUST be used for only csci315 at UDC // #include #include #include #include #include #include #include #include #define PORTNUM 2400 #define MAXRCVLEN 500 int main(int argc, char *argv[]) { char* msg = "HI CSCI315\n"; char buffer[MAXRCVLEN + 1]; int len, consocket; struct sockaddr_in dest; struct sockaddr_in serv; int mysocket; socklen_t socksize = sizeof(struct sockaddr_in); memset(&serv, 0, sizeof(serv)); serv.sin_family = AF_INET; serv.sin_addr.s_addr = htonl(INADDR_ANY); serv.sin_port = htons(PORTNUM); mysocket = socket(AF_INET, SOCK_STREAM, 0); bind(mysocket, (struct sockaddr *)&serv, sizeof(struct sockaddr)); do{ listen(mysocket, 1); consocket = accept(mysocket, (struct sockaddr *)&dest, &socksize); send(consocket, msg, strlen(msg), 0); while(len=recv(consocket, buffer, MAXRCVLEN, 0)>0){ if(strncmp(buffer, "exit", 4) == 0){ break; } printf("Server Received: %s ", buffer); memset(buffer, 0, strlen(buffer)); } printf("Goodbye !\n"); close(consocket); }while(consocket); close(mysocket); return EXIT_SUCCESS; }
Sharing a channel Wired Networks Wireless Networks

Tutor Answer

(Top Tutor) Studypool Tutor
School: Rice University
Studypool has helped 1,244,100 students
flag Report DMCA
Similar Questions
Hot Questions
Related Tags
Study Guides

Brown University





1271 Tutors

California Institute of Technology




2131 Tutors

Carnegie Mellon University




982 Tutors

Columbia University





1256 Tutors

Dartmouth University





2113 Tutors

Emory University





2279 Tutors

Harvard University





599 Tutors

Massachusetts Institute of Technology



2319 Tutors

New York University





1645 Tutors

Notre Dam University





1911 Tutors

Oklahoma University





2122 Tutors

Pennsylvania State University





932 Tutors

Princeton University





1211 Tutors

Stanford University





983 Tutors

University of California





1282 Tutors

Oxford University





123 Tutors

Yale University





2325 Tutors