Question: Write a program to make the UDP client program in Table 25.2 more generic to be able to send any request created by the client

Write a program to make the UDP client program in Table 25.2 more generic to be able to send any request created by the client program.

Table 25.2 Echo client program using UDP I/ UDP echo client program #include

Table 25.2 Echo client program using UDP I/ UDP echo client program #include "headerFiles.h" int main (int arge, char* argv[ ]) // Three arguments to be checked later // Declare and define variables int s; I/ Socket descriptor 6. // Length of string to be echoed // Server name int len; char* servName; I/ Server port // String to be echoed // Data buffer // Server socket address int servPort; char* string; char buffer [256 + 1]; 10 12 struct sockaddr_in servAddr; I/ Check and set program arguments if (argc != 3) 13 14 15 16 printf ("Error: three arguments are needed!"); exit(1): servName=argv[1]; servPort = atoi (argv[2]); string = argv[3]; // Build server socket address memset (&servVAddr, 0, sizeof (servAddr)): servAddr.sin_family = AF_INET; inet_pton (AF_INET, servName, &servAddr.sin addr); servAddr.sin port = htons (servPort): // Create socket if ((s = socket (PF_INET, SOCK_DGRAM, 0) < 0); perror ("Error: Socket failed!"): exit (1); I/ Send echo string len = sendto (s, string, strlen (string), 0, (struct sockaddr)&servAddr, sizeof (servAddr)); I/ Receive echo string recvfrom (s, buffer, len, 0, NULL, NULL); // Print and verify echoed string 38 buffer [len] = "0'; printf ("Echo string received: "; fputs (buffer, stdout); I/ Close the socket 40 41 close (s);s 43 // Stop the program 44 exit (0): 45 J// End of echo client program

Step by Step Solution

3.31 Rating (166 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

This is the general UDP client program in the C langu... View full answer

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 Computer Networking Questions!