Socket Classes and Functionality Overview

team bbl


At the core of socket operations is wxSocketBase, which provides the basic socket functionality for sending and receiving data, closing, error reporting, and so on. Establishing a listening socket or connecting to a server requires wxSocketServer or wxSocketClient, respectively. wxSocketEvent is used to notify the application of an event that has occurred on a socket. The abstract class wxSocketBase and its children such as wxIPV4address enable you to specify remote hosts and ports. Lastly, stream classes such as wxSocketInputStream and wxSocketOutputStream can be coupled with other streams to move and transform data over a socket. Streams were discussed in Chapter 14, "Files and Streams."

Sockets in wxWidgets can operate in different ways, as discussed later in the "Socket Flags" section. The traditional threaded socket approach is handled by disabling the socket events and using blocking socket calls. On the other hand, you can enable socket events and eliminate the need for a separate thread; wxWidgets will send an event to your application when processing is required on a socket. By letting the data arrive in the background and processing data only when it is present, you avoid blocking the GUI, and you avoid the complexity of putting each socket in its own thread.

This chapter provides examples of both methods as well as a thorough explanation of the API for wxSocket and related classes. The examples and reference can be read and used independently, although the examples are intended to preface the explanation of the APIs.

    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

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