From the course: Network Programming in C: Develop Reliable Client/Server Applications
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
Solution: Code a UDP client and server - C Tutorial
From the course: Network Programming in C: Develop Reliable Client/Server Applications
Solution: Code a UDP client and server
(jaunty music) - [Instructor] For my solution, I coded the UDP server first, then the client, then I spent a lot of time debugging. First, the server, shown here. This is this string reversal function. It's passed one string and returns that string reversed. The string returned, reversed, is classified as static. So its contents are retained when the function quits. Storage is allocated for the string, and then a loop processes the sent string back to front to reverse it. Comments in the code explain the details. Onto the main function. A UDP socket is set at line 54. Line 56 configures the local host to use port 8080. A socket file descriptor is obtained at line 64. The bind function appears at line 72 and at this point, the UDP server is ready for an incoming connection. To handle that, the receive from function is used at line 82. This is where the client's address is obtained here at line 87. The string…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.