Sockets Exercise: ----------------- Change the files that were used in class in order to do the following: 1. all socket connections should happen at port 5503 2. when running the client/server application, we needed to use the IP address of the server, to be able to connect to it. Rewrite some parts of the application to be able to access the server by hostname. For example, instead of running: tcpechoclient 18.58.0.236 you will run: tcpechoclient list.mit.edu For that part of the exercise, you may want to use gethostbyname() instead of gethostbyaddr() Remember that you only need to pass the server name as argument for gethostbyname() 3. our initial client/server application uses TCP as its transport layer. We would like to change that in order to have UDP running instead. Let's explore what we need to change in order to achieve that: A. Remember that you have to use SOCK_DGRAM instead of SOCK_STREAM B. UDP is a much smaller protocol than TCP. It is connectionless, so there is no need to connect/listen/accept. Delete or comment out all the code that was used for those functions. D. We will not need any of the lines from: newsockfd = accept .... all the way to the line before: while (read(...) Also, since we do not use newsockfd in this case, reading and writing should happen at the sockfd socket, so change the reading/writing/closing to take sockfd instead. No need for the exit(EXIT_SUCCESS) either. C. Since we don't open a connection to a certain address/port, we need to send the server address everytime we send packets of data. So, we cannot use read/write, that do not have functionality for client and server addresses. So, let's change read() and write() to recvfrom() and sendto() respectively. The functions are as follows: sendto(sockfd, &outbuffer, 1, 0, &serveraddr, sizeof(serveraddr)) instead of: write(sockfd, &outbuffer, 1) and: recvfrom(sockfd, &inbuffer, 1, 0, &serveraddr, &serveraddrlength) instead of: read(sockfd, &inbuffer, 1) P.S: You will need to declare: serveraddrlength = sizeof(serveraddr); before using it in the client program, just like it is used in the server program Write 2-3 lines about the main differences between UDP and TCP as comments in your code To do that, put the text that you write between /* text goes here */ Coding: ------- For parts 1 and 2, make the changes in one set of files and save the files as: for client: athena_username_client.c for server: athena_username_server.c For part 3, make changes to different copies and name them: for client: athena_username_udp_client.c for server: athena_username_udp_server.c where you replace athena_username by your username Submission: ----------- submit all your code by email attachment. Help: ----- Send email to: richard@list.mit.edu