Chapter 8: Sockets Programming Pitfalls

 < Day Day Up > 



Although Sockets programming is conceptually simple, improperly using the API or not taking into account protocol behaviors can induce errors within network applications. In this chapter, we investigate some common and not-so-common pitfalls that can be found in common network applications, and then explain how to correct them.

Introduction

A number of programming pitfalls are discussed in this chapter. Some pitfalls concentrate on improper usage of the BSD API, whereas others explore protocol behavior effects on the API. The common pitfalls that are discussed in this chapter include:

  • Failing to use function returns

  • Ignoring peer socket closure

  • Ignoring endianness of parameters in API functions

  • Making protocol framing assumptions

  • Causing “Address in use” error for bind

  • Listening on multiple interfaces

  • Initial UDP datagrams disappearing

  • Defensive programming

    • Using safe functions to avoid buffer overflow

    • Rigorously checking error returns

    • Rigorously checking input and output parameters

    • Declaring string arrays

    • Minimizing protocol feedback

    • Initializing all variables

    • Enabling all compiler warnings



 < Day Day Up > 



BSD Sockets Programming from a Multi-Language Perspective
Network Programming for Microsoft Windows , Second Edition (Microsoft Programming Series)
ISBN: 1584502681
EAN: 2147483647
Year: 2003
Pages: 225
Authors: Jim Ohlund

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net