Summary
Windows Sockets allows the use of an industry-standard API, so that your programs can be interoperable and nearly portable in source code form. Winsock is capable of supporting nearly any network protocol, but TCP/IP is the most common.Winsock is comparable to named pipes (and mailslots) in both functionality and performance, but portability and interoperability are important reasons for considering sockets. Keep in mind that socket I/O is not atomic, so it is necessary to take care to ensure that a complete message is transmitted.This chapter has covered the Winsock essentials, which are enough to build a workable system. There is, however, much more, including asynchronous usage; see the Additional Reading references for more information.This chapter also provided examples of using DLLs for in-process servers and for creating thread-safe libraries.
Looking Ahead
Chapters 11 and 12 have shown how to develop servers that respond to client requests. Servers, in various forms, are common Windows applications. Chapter 13 describes Windows Services, which provide a standard way to create and manage servers, in the form of services, permitting automated service start-up, shutdown, and monitoring. Chapter 13 shows how to turn a server into a manageable service.
Additional Reading
Windows Sockets
Windows Sockets Network Programming, by Bob Quinn and Dave Shute, and its supporting site, http://www.sockets.com , are dedicated to Windows sockets. However, the book is outdated in many ways, and threads are never used. Many readers will find the following books more helpful.
Berkeley Sockets and TCP/IP
W. R. Stevens' TCP/IP Illustrated, Volume 3, covers sockets and much more, while the first two volumes in the series describe the protocols and their implementation. The same author's UNIX Network Programming provides comprehensive coverage that is valuable even for non-UNIX systems. Other good references are Douglas E. Comer and David L. Stevens, Internetworking with TCP/IP, Volume III, and Michael Donahoo and Kenneth Calvert, TCP/IP Sockets in C: Practical Guide for Programmers.