CHAPTER 12 NETWORK PROGRAMMING WITH WINDOWS SOCKETS
In this chapter, the client/server system is used as a vehicle for demonstrating
Winsock, and, in the course of modifying the server, interesting new features are
added. In particular, DLL entry points (Chapter 5) and in-process DLL servers are
used for the first time. (These new features could hav
e been incorporated in the
initial Chapter 11 version, but doing so would have di stracted from the d evelop-
ment and understanding of the basic system architecture.) Finally, additional
examples show how to create reentrant thread-safe libraries.
Winsock, because of conformance to ind
ustry standards, has naming
conventions and programming characteristics somewhat different from the
Windows functions described so far. T he W insock API is not strictly a part of Win32/
64. Winsock also provides additional functions that are not part of the standard;
these functions are used only as absolutely required. Among other advantages,
programs will be more portable to other systems.
The Winsock API was developed as an extensi on of the Berkeley Sockets API into
the Windows environment, and Winsock is supported by all Windows systems.
Winsock’s benefits include the following.
•Porting of code already written for Berkeley Sockets is straightforward.
indows systems easily integrate into TCP/IP networks, both IPv4 and the
emerging IPv6. IPv6, among other features, allows for longer IP addresses,
overcoming the 4-byte address limit of IPv4.
•Sockets can be used with Windows overlapped I/O (Chapter 14), which, among
other things, allows servers to scale when there is a large number of active cli
•Sockets can be treated as file
s for use with , ,
a nd, with some limitations, other Windows functions, just as UNIX allows
sockets to be used as file descriptors. This capability is convenient whenever
there is a need to use asynchronous I/O and I/O completion ports (Chapter 14).
•Extended, nonportable extensions are also available.
The Winsock API is supported by a DLL ( ) that can be accessed by
with your program. The DLL needs to be initialized with a
nonstandard, Winsock-specific function,
, which must be the first
Winsock function a program calls.
should be called when the pro-
gram no longer needs to use Winsock functionality. Note: The prefix