📄 index.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN"><html lang="en"><head><title>Winsock Programmer's FAQ: Basic Example Programs</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/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 </b></p> </font> </td> <td align="right" bgcolor="#e0e0c0"> <font size="2" face=Verdana,Arial,Helvetica> <b><a href="../../examples/basics/basic-client.html">>></a></b> </font> </td> </tr></table><!-- ---- Body Table ---- --><table width="95%" border="0" cellpadding="10"> <tr valign="top"> <td><p>These examples show you how to implement several basic kinds ofclient and server programs. All the client programs simply connect toan echo server, send a packet of data, read the echoed reply back fromthe server, check that the data in the reply packet is what was sent,and exit. The server programs implement various forms of the echo serveridea. (You can also use a standard "port 7" echo server available as anoption on many Unix boxes and Windows NT/2000.) The echo server idea letsus focus more on the structure of the program and less on its function,and yet still provide a fairly functional program.</p><p>Although these programs are "minimal" in the sense that they don'tdo much, they are still complete in that they do all the proper errorchecking, shut their connections down gracefully, are fully commented,etc. Some thought has been given to making it easy to swipe pieces ofcode from these examples.</p><p>These programs all follow the same form as much as possible. Anytime you find two functions named the same in two differentexamples, you can be sure that they have the same function,so you can study them comparatively. For example, you can study<code>EstablishConnection()</code> in the basic and asynchronous clientsto see how "going asynch" changes the way you handle a connectionattempt.</p><p>Right now, I only have one simple client and one simple serverhere, but more are soon to come, as I find the time. The nextprogram will be a multi-connection multithreaded server, and thena <code>select()</code>-based server. After that, I'll implementasynchronous clients and servers with straight Win32 API code. Nextwill come overlapped I/O clients and servers. After that, readercomments will guide me. Two other ideas I have in mind are examplesthat use I/O completion ports and the MFC CSocket/CAsyncSocketclasses. I may even present an example that uses my <ahref="../../../endpoint/index.html">Endpoint</a> class library.</p><h3>Support Files</h3><p>You should probably download all of these before you begin, becauseall examples require at least one of these files.</p><ul> <p><b><a href="Makefile">Makefile</a></b> - The Makefile (Borland andMicrosoft C++-compatible) that builds the examples. (Not required,but makes building the examples easier.)</p><p><b><a href="main.cpp">main.cpp</a></b> - The <code>main()</code> function forthe console-mode example programs. Parses the command line, initializesWinsock, calls the example's driver function, and then shuts Winsockback down.</p><p><b><a href="ws-util.cpp">ws-util.cpp</a></b> - A set of Winsock utility functionsused by more than one example program.</p><p><b><a href="ws-util.h">ws-util.h</a></b> - Header file for ws-util.cpp.</p> </ul><h3>The Examples</h3><p>These are the main example files. Each example comes in a singlefile; the header comment in that file tells you which other modulesit requires.</p><p>Each of these examples illustrates a particular design choice. Youcan find answers on "which choice is better" for a given application in<a href="../../tutorials/socket-types.html">Tutorial 1</a>. Obviously,no one design choice is best for all situations, or we would not have somany choices. Between the Tutorial's advice and these concrete examples,you should be able to make your decision fairly easily.</p><ul> <p><b><a href="basic-client.html">Basic blocking client</a></b> - Aclient that uses blocking sockets. This is the simplest of theprograms here.</p><p><b><a href="basic-server.html">Basic blocking server</a></b> - Asingle-connection server that uses blocking sockets.</p> </ul> </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/index.html"><< Example Programs</a> </td> <td align=right> <a href="../../examples/basics/basic-client.html">Basic Blocking Client >></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 + -