[ LiB ] |
Back in Chapter 2, "Winsock/Berkeley Sockets Programming," I introduced you to the API for plain vanilla -flavored BSD sockets. Throughout that chapter, you may have noticed my distaste for the API, which is decades old and has clearly started to show its age lately. I particularly dislike how much code it takes to actually get something done. Think about it. It takes at least 12 lines of code to get a single listening socket created, and that doesn't even count error-handling code. I look at many MUDs out there, and I see socket code thrown in every which way. Most MUDs are a maintenance disaster because of this. If you want to do something correctly, you're going to have to design for it up front.
So that's the approach I'm taking with this chapter. I've created a comprehensive and flexible Socket Library for you (located on the CD in the directory /Libraries/SocketLib/). This library has two levels: classes that directly interface with the Sockets API ("wrapper" classes), and classes that build on top of those wrappers.
In this chapter, you will learn to:
Create a flexible object-oriented socket hierarchy
Abstract the Sockets API select function into a class
Create an advanced policy-based connection class
Create a class to manage listening sockets
Create a class to manage connections
[ LiB ] |