Contents Up Previous Next

wxSocketServer

Derived from

wxSocketBase

Include files

<wx/socket.h>

Members

wxSocketServer::wxSocketServer
wxSocketServer::~wxSocketServer
wxSocketServer::Accept
wxSocketServer::AcceptWith
wxSocketServer::WaitForAccept


wxSocketServer::wxSocketServer

wxSocketServer(const wxSockAddress& address, wxSocketFlags flags = wxSOCKET_NONE)

Constructs a new server and tries to bind to the specified address. Before trying to accept new connections, test whether it succeeded with wxSocketBase:IsOk.

Parameters

address

flags


wxSocketServer::~wxSocketServer

~wxSocketServer()

Destructor (it doesn't close the accepted connections).


wxSocketServer::Accept

wxSocketBase * Accept(bool wait = true)

Accepts an incoming connection request, and creates a new wxSocketBase object which represents the server-side of the connection.

If wait is true and there are no pending connections to be accepted, it will wait for the next incoming connection to arrive. Warning: This will block the GUI.

If wait is false, it will try to accept a pending connection if there is one, but it will always return immediately without blocking the GUI. If you want to use Accept in this way, you can either check for incoming connections with WaitForAccept or catch wxSOCKET_CONNECTION events, then call Accept once you know that there is an incoming connection waiting to be accepted.

Return value

Returns an opened socket connection, or NULL if an error occurred or if the wait parameter was false and there were no pending connections.

See also

wxSocketServer::WaitForAccept, wxSocketBase::SetNotify, wxSocketBase::Notify, wxSocketServer::AcceptWith


wxSocketServer::AcceptWith

bool AcceptWith(wxSocketBase& socket, bool wait = true)

Accept an incoming connection using the specified socket object.

Parameters

socket

Return value

Returns true on success, or false if an error occurred or if the wait parameter was false and there were no pending connections.

wxSocketServer::WaitForAccept, wxSocketBase::SetNotify, wxSocketBase::Notify, wxSocketServer::Accept


wxSocketServer::WaitForAccept

bool WaitForAccept(long seconds = -1, long millisecond = 0)

This function waits for an incoming connection. Use it if you want to call Accept or AcceptWith with wait set to false, to detect when an incoming connection is waiting to be accepted.

Parameters

seconds

millisecond

Return value

Returns true if an incoming connection arrived, false if the timeout elapsed.

See also

wxSocketServer::Accept, wxSocketServer::AcceptWith, wxSocketBase::InterruptWait