OWLNext 7.0
Borland's Object Windows Library for the modern age
|
The TSocket class encapsulates a Winsock SOCKET.
It simplifies the use of SOCKETs while letting you fall back to Winsock API calls if desired. For example, the TSocket class allows you to say:
Whereas in Winsock, you would have to say:
You can use a TSocket class anywhere you can use a SOCKET identifier, since class TSocket provides an automatic conversion operator from TSocket to SOCKET. So if you really want to use the Winsock API, you can say:
TSocket offers a number of methods for construction. These are the default constructor, a constructor from an TSocketAddress and protocol info, and a copy constructor. The construction from a TSocketAddress and protocol info is the most common form. You would say something like the following:
or, equally
The TSocket class provides socket creating, binding, and closing functions, read and write functions, socket option setting and getting functions, and more. In actuality, you will most often use the TSocket-derived TStreamSocket and TDatagramSocket, especially for reading and writing the socket.
The Socket class supports both blocking and non-blocking socket operation. By default, the Socket class blocks on calls to Read and Write, etc. But, like in the Winsock API, you can turn on asynchronous notification of events like FD_READ, etc. In the Socket class, you use the StartRegularNotification(), StartAcceptNotification(), and CancelNotification() functions. These functions cause the Socket functions DoReadNotification(), etc. to be called when the appropriate FD_READ, etc. messages are sent to an internal Socket hidden window. You can redirect these notifications to a given window of your choice with the Socket SetNotificationWindow() and SetNotificationSet() functions. This way, you get full flexibility with Socket asynchronous notifications.
The TSocket class (and its subclasses) optionally supports read/write data queueing during asynchronous operation. This allows you to tell the socket to send a block of data with one send and have the Socket save that block of data and send it automatically as soon as possible; you don't have to wait for a notification to come-the Socket will take care of that for you. This queueing also applies to data receiving. You have TSocket bring the data in and wait until it gets to a certain size and then get what you want from the queue.