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,500 courses taught by industry experts.

Solution: A generic TCP client

Solution: A generic TCP client

(lively music) - [Instructor] Here is my solution, which follows the pattern for a TCP client. The key functions are, get address info at line 19, socket at line 27, connect at line 35, and at this point the send function is used to send a chunk of text. Then the receive function receives whatever the response could be. This is all the interaction necessary. Then memory is freed and the socket is closed, the client quits. Here are the specifics. Line 12 sets the string to send to the server. At line 16, the hints structure is initialized. Remember, to use the memset S function if it's available in your compiler, as opposed to memset. The connection is IPV four and the protocol is TCP. The host is set here using the local host IPV four address, port 8080. Socket is created. A connection is made and once established, communications can take place with a host. The hello string is sent at line 43, and then line…

Contents