📄 basic-client.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><html lang="en"><head><title>Winsock Programmer's FAQ: Basic Blocking Client</title><link rel="Stylesheet" type="text/css" href="../../faq.css"></head><body bgcolor="#ffffee" text="#000000" link="#491e00" vlink="#7d2e01" alink="#da7417"><!-- ---- Header Bar ---- --><table border="0" width="95%" bgcolor="#006000" cellpadding="5" cellspacing="3" align="center"> <tr> <td align="left" bgcolor="#e0e0c0"> <font size="2" face=Verdana,Arial,Helvetica> <b><a href="../../examples/basics/index.html"><<</a></b> </font> </td> <td align="center"> <font face=Verdana,Arial,Helvetica color="#ffffee"> <p align=center class=bigger3><b> Winsock Programmer's FAQ<br> Basic Winsock Examples: Blocking Client </b></p> </font> </td> <td align="right" bgcolor="#e0e0c0"> <font size="2" face=Verdana,Arial,Helvetica> <b><a href="../../examples/basics/basic-server.html">>></a></b> </font> </td> </tr></table><!-- ---- Body Table ---- --><table width="95%" border="0" cellpadding="10"> <tr valign="top"> <td><p>This client is the simplest possible client, if you counterror-checking and reporting, proper connection shutdown, helpful commentsand name lookup as essential. You can strip all that out and have a muchshorter program, though I can't imagine why you'd want such a thing.</p><p>Like all the examples, the real work starts out in<code>DoWinsock()</code> which the common <code>main()</code> functionin <a href="main.cpp">main.cpp</a> calls.</p><p>The example then does a DNS lookup on the remote peer's address,if necessary. Notice that in <code>LookupAddress()</code> wetest the address with <code>inet_addr()</code> to see if it's a <ahref="../../glossary.html#dotted-quad">dotted-quad</a> address. If it is,<code>inet_addr()</code> will return the address in binary form, whichwe can return to the caller. Otherwise, we assume that the address isa <a href="../../glossary.html#domain-name">domain name</a> and attemptto look it up with the <code>gethostbyname()</code> function.</p><p>The example then executes the same echo sequence that all the clientsin this series implement. All this comes to just over 100 lines of realcode. That might seem like a lot for such a basic program, but as you'llsee, the blocking nature of this program makes it very simple comparedto the other client programs.</p><p>The only module you will need to compile this program,aside from the common files listed on the main examples page, is<a href="basic-client.cpp">basic-client.cpp</a>. The comment at the top of the file givescomplete compilation instructions; alternately, you can use the common<a href="Makefile">Makefile</a>.</p> </td> </tr></table><!-- ---- Document Footer ---- --><hr noshade size=1 color=#404040><table cellpadding=5 cellspacing=0 border=0 width=95% align=center> <tr> <td align=left> <a href="../../examples/basics/index.html"><< Basic Example Programs</a> </td> <td align=right> <a href="../../examples/basics/basic-server.html">Basic Blocking Server >></a> </td> </tr> <tr> <td align=left> <i>Last modified on 29 April 2000 at 15:52 UTC-7</i> </td> <td align=right> <font size=-1>Please send corrections to <a href="mailto:tangent@cyberport.com">tangent@cyberport.com</a>.</font> </td> </tr> </table> <table cellpadding=5 cellspacing=0 border=0 width=95% align=center> <tr> <td align=left width=33%> <font size=-1> <a href="../../index.html"><b><</b> Go to the main FAQ page</a> </font> </td> <td width=33%> <font size=-1> <center> <a href="http://www.cyberport.com/~tangent/programming"><b><<</b> Go to my Programming pages</a> </center> </font> </td> <td align=right width=33%> <font size=-1> <a href="http://www.cyberport.com/~tangent/"><b><<<</b> Go to my Home Page</a> </font> </td> </tr> </table> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -