Manning Publications
TCP/IP Programming
for OS/2


Inside the book
Contents
Preface
Chapter 1
Chapter 10
Index

About the book
Readers also bought
From the experts
About the author

The Publisher
In press
Under development
Recently published
Catalog
Contact us

Order
Preface

I first saw OS/2 version 1.0 in 1988 after IBM and Microsoft teamed up to create a replacement for DOS. Even though only seven years have passed, it all seems like ancient history. At that time, I was a dyed-in-the-wool DOS programmer, and Windows was still too immature to be a contender for my affections. I attended a product debut for OS/2, and I remember being excited about the arrival of a real multitasking operating system for the 80x86 platform.

Looking back today, I wonder what I could have been thinking. Here was an operating system designed for the aging 80286, with poor (to say the least) DOS support, and system requirements that were well out of the reach of most users. That first version had no networking capabilities to speak of and no graphical user interface, two items high on every user's checklist of requirements for a desktop operating system today. When my initial excitement faded away, I left OS/2 for dead - although with each new release I snatched another glimpse, just in case things had improved. However, OS/2 1.x was never the development platform I wanted. Even though enhancements such as Presentation Manager (PM) and networking were added, there always seemed to be something missing.

In April 1992, while attending the Borland Developers' Conference in Monterey, California, our paths crossed once again. This time it was version 2.0, IBM's first solo version after having shaken free of Microsoft, who was now married to Windows 3.0. I remember how bitter I had become toward IBM and OS/2, and as I sat down to an OS/2 demonstration system, I had one intention - to crash it. However, I played with 2.0 for a while and quickly became enamored with its features and stability. I clearly remember uttering words like "wow" and "neat" as I moused around the new OS/2 Workplace Shell. Finally, here was an operating system that could fill my needs. It still lacked some gloss, but it was truly an operating system with the potential to replace DOS and Windows.

By November 1992, I was a confirmed OS/2 fanatic. I purchased the OS/2 Professional Developers' Kit from IBM, and devoured every word ever printed on the subject of OS/2. Early in 1994, I formed NeoLogic Inc., which specializes in improving user perception of OS/2, TCP/IP, and the Internet. NeoLogic took shareware applications I had been developing since 1992 and expanded them into a product called the NeoLogic Network Suite, which now includes several applications, including a full-featured news reader, Gopher, FTP, and mail.

With each new application, I have become more (sometimes painfully) aware of OS/2's features and limitations. I developed a set of simple C++ classes to help produce applications more rapidly and with fewer bugs. While developing my applications, it became obvious that really good programmer documentation for OS/2 is rare. There are, of course, many books "for dummies" which describe these topics from a new user's perspective, but I found few books "for techno-geeks." This raises the obvious question: Are other OS/2 developers having the same problems that I faced in the early stages of my OS/2 experience?

Based on the availability and quality of OS/2 applications, the answer to this question is a very vocal "Yes." Many aspiring developers have sent me e-mail asking how to manipulate some aspect of the OS/2 API or TCP/IP socket interface. In short, people were expressing interest in how the news program was written - not because they are all that interested in News itself; rather, they wanted to know things about programming for OS/2 and how to use the TCP/IP socket interface. Although I never professed to be an "expert" on either of these subjects, I have managed to unearth more information than most OS/2 programmers. This book is the direct result of my research into developing TCP/IP applications for OS/2, and I am taking the opportunity to share this knowledge with everyone.

Steven Gutz
nstn4064@fox.nstn.ca


Who is the Intended Audience?

This book is intended to span the basics of developing TCP/IP applications for the OS/2 family of operating systems. I have placed emphasis on the C++ programming language and the Presentation Manager interface, although most information in the book applies equally to C and OS/2 Text Mode. Where possible, I have described the C++ code at the method (member function) level in order to improve portability to C.

Like any multitasking operating system, developing applications for OS/2 is definitely not for the faint of heart. Furthermore, if you are planning to build programs designed for TCP/IP interaction, be prepared for many headaches along the way. However, I will do my best to lead you through the process of building simple TCP/IP clients from start to finish. I will make a few side trips along the way to describe the additional complications that the Presentation Manager interface adds. I hope that by the time you finish reading this book, you will have the knowledge to attack your own PM and TCP/IP projects with confidence.

Before we begin, I should describe my assumptions of you. You will, of course, need to be an intermediate- to advanced-level programmer, preferably possessing some experience with OS/2. If you have never programmed in OS/2, Windows, or other message-based OS, then this book is definitely not for you. I will initially present a few minimal programming examples, but I will quickly ramp up to building dynamic link libraries and workable applications. I will dive right into advanced topics, like the use of PM Container controls, once we get through the preamble in the first part of this book.

I will assume that you know and fully understand the C++ programming language and the concepts of object-oriented programming. Although the applications developed will sometimes be a hybrid of C and C++, emphasis is definitely directed toward developing solid, portable class libraries. Most of the source code for the class libraries is written completely in C++.

Finally, I will assume that you have some understanding of TCP/IP, at least from a user perspective. You do not need to be a network programming "guru" by any means, but you will find that some experience with TCP/IP socket programming is a definite asset, and working knowledge of TCP/IP applications is essential. I will not delve too deeply into the inner workings of TCP/IP since there are many excellent books on the subject. Rather, I will describe the basic network source code used for the socket interface, and will require that you possess only a minimal background knowledge of what is inside TCP/IP.


How This Book Is Organized

This book consists of three parts. We begin with a little background on OS/2, TCP/IP, and the Internet, and finish with a handful of working applications and the knowledge to build your own programs. The book is organized as follows:

  • Part I contains all the information you will need to get started, including a quick discussion of OS/2, TCP/IP, the Internet, and what tools you require and how to set them up.

  • Part II contains lots of detailed code as we develop and examine class libraries for the user interface and for networking.

  • In Part III we will create several working applications designed to demonstrate the class libraries.

  • The Appendices contain reference guides for the User Interface and Network class libraries.


Conventions Used in This Book

In order to present the information contained in this book in a consistent manner, the following conventions are used throughout:

  • Except where noted, commands, filenames, and extensions are capitalized (e.g., CONFIG.SYS).

  • This book uses a particular notation for illustrating program objects. An object will be drawn as follows:
OBJECT NAME
Attribute 1
Attribute 2


  • Attribute n
  • Method 1
    Method 2


  • Method n
  • Object inheritance will be illustrated as:


    Source code in this book will follow a coding convention based loosely on Hungarian notation, originally devised by Charles Simonyi of Microsoft Corp. If you have never used this notation it might at first seem strange, but it does help write better code. The notation consists of prefix character(s) for variable names as follows:

    Prefix     Data Type
    c
    by
    b
    h
    l
    sz
    ul
    Character
    BYTE or unsigned character
    BOOL Boolean type
    Handle to windows, files, etc.
    LONG integer
    NULL terminate character string
    ULONG unsigned long integer
    When creating instances of structured data types, variable names will be prefixed as follows:
    Prefix     Data Type
    xs
    xt
    xc
    Instance of a structure (struct)
    Instance of a type (typedef)
    Instance of a class (class)

    Some additional modifiers will be used, as shown below:

    Prefix     Data Type
    p
    g
    Pointer to a selected data type
    Global data

    Finally, all classes, type definitions, and data structures will be defined using UPPERCASE characters, preceded by one of the following prefixes:

    Prefix     Data Definition
    S_
    T_
    C_
    Structure definition (Example: S_USER_DATA)
    Type definition (Example: T_ADDRESS)
    Class definition (Example: C_WINDOW)


    Using This Book

    This book is not meant to be read cover-to-cover before delving into the knowledge you will find within it. Indeed, I certainly didn't write it from cover-to-cover; rather, it evolved as I rewrote sections several times. The class libraries were recoded again and again. Each time I added a feature to one of the applications in Part III, I realized that I had neglected to add a required method to one of the PM classes, or had forgotten to write a class completely. Since all the library code is written in C++, adding or modifying parts was usually a trivial exercise.

    This is the approach I would like you to take in reading and using this book. The classes I have provided are only a basic framework, and I expect you will want to add your own features and extensions to the class libraries. You will, of course, need to add new objects to the network class library in order to implement interfaces for additional network protocols, such as mail or IRC, but you may also want to add new members to some of the PM classes, since you will likely find some omissions made either by accident or intention. The possibilities for enhancements to the classes in this book are limitless - if you are familiar with Borland's OWL or IBM ICLUI class libraries, you know what sorts of features can be added. The beauty of the object-oriented approach of C++ is that, if you decide you want your window object to do more, then you may subclass the one I have provided and add your own extensions, reusing only what you need.


    About the Companion Disk

    This book includes a companion disk containing all the code for the libraries and applications developed in the latter sections of the book. This will save you many hours of work when you begin developing your own applications. The disk also contains some of my favorite freeware and shareware applications, as well as copies of some of the RFCs referenced in the book.

    The source code contained on the companion disk will compile with either the Borland C++ for OS/2 package or IBM VisualAge C++ for OS/2, and project files have been provided for both compilers.

    Finally, the companion disk includes pre-built libraries and DLLs which can be used with the VisualAge C++ compiler. Executables for the Editor, news, FTP, and Ping are also included on the disk.

    To install the companion disk, insert the disk and from an OS/2 command line type: "D:<Enter>", where "D:" is the drive letter of your disk drive. Then type "INSTALL<Enter>" to begin the installation process.


    Special Thanks

    There are a number of people I would like to thank for assisting with the creation of this book. Most of you have no knowledge of the contributions you have made, but you have been helpful in ways which cannot be imagined.

    To my wife, Nancy, a mother and a business woman, who still managed to tolerate all of my demands and annoyances while I was creating this book.

    To David Reich, thank you for the OS/2 T-shirt, and for introducing me to "the new IBM." Our candid discussions of OS/2 were instrumental in filling in a great deal of background information.

    To David Moskowitz, I am grateful for our candid conversations at the Borland Developer's Conferences and in e-mail over the past few years. Thanks also for your input and suggestions as a beta tester for the NeoLogic Network Suite.

    To Len Dorfman, thanks for asking the simple question, "Would you like to write a book?" Thanks also for proofreading my incomplete draft copies.

    To Tim McGinn, thanks for looking after some of the software development at NeoLogic while I was distracted writing this book.

    To all OS/2 users - without you, there would be no reason for this book. OS/2 is a nice place to set up business and you are all great neighbors.