Constructor & Destructor Documentation

Notice that if the object is created from a worker thread or if it is created from the main thread but the event loop is not running, flags parameter must include wxSOCKET_BLOCK as non-blocking sockets require dispatching events, which can only be done in the main thread.

If wait is false, Connect() will try to establish the connection and return immediately, without blocking the GUI. When used this way, even if Connect() returns false, the connection request can be completed later. To detect this, use WaitOnConnect(), or catch wxSOCKET_CONNECTION events (for successful establishment) and wxSOCKET_LOST events (for connection failure).

Parameters

address

Address of the server.

wait

If true, waits for the connection to complete.

Returns

true if the connection is established and no error occurs. If wait was true, and Connect() returns false, an error occurred and the connection failed. If wait was false, and Connect() returns false, you should still be prepared to handle the completion of this connection request, either with WaitOnConnect() or by watching wxSOCKET_CONNECTION and wxSOCKET_LOST events.

If wait is true, Connect() will wait until the connection completes. Warning: This will block the GUI.

If wait is false, Connect() will try to establish the connection and return immediately, without blocking the GUI. When used this way, even if Connect() returns false, the connection request can be completed later. To detect this, use WaitOnConnect(), or catch wxSOCKET_CONNECTION events (for successful establishment) and wxSOCKET_LOST events (for connection failure).

Parameters

address

Address of the server.

local

Bind to the specified local address and port before connecting. The local address and port can also be set using SetLocal(), and then using the 2-parameter Connect() method.

wait

If true, waits for the connection to complete.

Returns

true if the connection is established and no error occurs. If wait was true, and Connect() returns false, an error occurred and the connection failed. If wait was false, and Connect() returns false, you should still be prepared to handle the completion of this connection request, either with WaitOnConnect() or by watching wxSOCKET_CONNECTION and wxSOCKET_LOST events.

WaitOnConnect() returns true if the connection request completes. This does not necessarily mean that the connection was successfully established; it might also happen that the connection was refused by the peer. Use wxSocketBase::IsConnected() to distinguish between these two situations.