Contents Up Previous Next

wxSocketClient

Derived from

wxSocketBase

Include files

<wx/socket.h>

Members

wxSocketClient::wxSocketClient
wxSocketClient::~wxSocketClient
wxSocketClient::Connect
wxSocketClient::WaitOnConnect


wxSocketClient::wxSocketClient

wxSocketClient(wxSocketFlags flags = wxSOCKET_NONE)

Constructor.

Parameters

flags


wxSocketClient::~wxSocketClient

~wxSocketClient()

Destructor. Please see wxSocketBase::Destroy.


wxSocketClient::Connect

bool Connect(wxSockAddress& address, bool wait = true)

Connects to a server using the specified address.

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

wait

Return value

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.

See also

wxSocketClient::WaitOnConnect, wxSocketBase::SetNotify, wxSocketBase::Notify


wxSocketClient::WaitOnConnect

bool WaitOnConnect(long seconds = -1, long milliseconds = 0)

Wait until a connection request completes, or until the specified timeout elapses. Use this function after issuing a call to Connect with wait set to false.

Parameters

seconds

millisecond

Return value

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 IsConnected to distinguish between these two situations.

If the timeout elapses, WaitOnConnect returns false.

These semantics allow code like this:

// Issue the connection request
client->Connect(addr, false);

// Wait until the request completes or until we decide to give up
bool waitmore = true; 
while ( !client->WaitOnConnect(seconds, millis) && waitmore )
{
    // possibly give some feedback to the user,
    // and update waitmore as needed.
}
bool success = client->IsConnected();
See also

wxSocketClient::Connect, wxSocketBase::InterruptWait, wxSocketBase::IsConnected