This client is the simplest possible client, if you count error-checking and reporting, proper connection shutdown, helpful comments and name lookup as essential. You can strip all that out and have a much shorter program, though I can't imagine why you'd want such a thing.

Like all the examples, the real work starts out in DoWinsock() which the common main() function in main.cpp calls.

The example then does a DNS lookup on the remote peer's address, if necessary. Notice that in LookupAddress() we test the address with inet_addr() to see if it's a dotted-quad address. If it is, inet_addr() will return the address in binary form, which we can return to the caller. Otherwise, we assume that the address is a domain name and attempt to look it up with the gethostbyname() function.

The example then executes the same echo sequence that all the clients in this series implement. All this comes to just over 150 lines of code. That might seem like a lot for such a basic program, but as you'll see, the blocking nature of this program makes it very simple compared to the other client programs.

The only module you will need to compile this program, aside from the common files listed on the main examples page, is basic-client.cpp. The comment at the top of the file gives complete compilation instructions; alternately, you can use the common Makefile.


<< Basic Example Programs
Asynchronous I/O Client >>
Updated Sun Jan 18 2015 04:24 MST   Go to my home page