| Version: 3.2.5

Public Member Functions | List of all members
wxSocketServer Class Reference
Class List by Category » Networking

`#include <wx/socket.h>`

Inheritance diagram for wxSocketServer:
[legend]

## Detailed Description

Todo:
  describe me.

##

Library: wxNet
Category: Networking

## Public Member Functions

| wxSocketServer (const wxSockAddress &address, wxSocketFlags flags=wxSOCKET_NONE)
| Constructs a new server and tries to bind to the specified address. More...
virtual | ~wxSocketServer ()
| Destructor (it doesn't close the accepted connections). More...
wxSocketBase * | Accept (bool wait=true)
| Accepts an incoming connection request, and creates a new wxSocketBase object which represents the server-side of the connection. More...
bool | AcceptWith (wxSocketBase &socket, bool wait=true)
| Accept an incoming connection using the specified socket object. More...
bool | WaitForAccept (long seconds=-1, long millisecond=0)
| Wait for an incoming connection. More...
Public Member Functions inherited from wxSocketBase
bool | Error () const
| Returns true if an error occurred in the last IO operation. More...
virtual bool | GetLocal (wxSockAddress &addr) const
| Return the local address of the socket. More...
virtual bool | GetPeer (wxSockAddress &addr) const
| Return the peer address field of the socket. More...
long | GetTimeout () const
| Return the socket timeout in seconds. More...
bool | IsConnected () const
| Returns true if the socket is connected. More...
bool | IsData ()
| Check if the socket can be currently read or written. More...
bool | IsDisconnected () const
| Returns true if the socket is not connected. More...
bool | IsOk () const
| Returns true if the socket is initialized and ready and false in other cases. More...
wxUint32 | LastCount () const
| Returns the number of bytes read or written by the last IO call. More...
wxUint32 | LastReadCount () const
| Returns the number of bytes read by the last Read() or ReadMsg() call (receive direction only). More...
wxUint32 | LastWriteCount () const
| Returns the number of bytes written by the last Write() or WriteMsg() call (transmit direction only). More...
wxSocketError | LastError () const
| Returns the last wxSocket error. More...
void | RestoreState ()
| Restore the previous state of the socket, as saved with SaveState(). More...
void | SaveState ()
| Save the current state of the socket in a stack. More...
virtual bool | Close ()
| Shut down the socket, disabling further transmission and reception of data and disable events for the socket and frees the associated system resources. More...
void | ShutdownOutput ()
| Shuts down the writing end of the socket. More...
wxSocketBase & | Discard ()
| Delete all bytes in the incoming queue. More...
wxSocketFlags | GetFlags () const
| Returns current IO flags, as set with SetFlags() More...
void | InterruptWait ()
| Use this function to interrupt any wait operation currently in progress. More...
wxSocketBase & | Peek (void *buffer, wxUint32 nbytes)
| Peek into the socket by copying the next bytes which would be read by Read() into the provided buffer. More...
wxSocketBase & | Read (void *buffer, wxUint32 nbytes)
| Read up to the given number of bytes from the socket. More...
wxSocketBase & | ReadMsg (void *buffer, wxUint32 nbytes)
| Receive a message sent by WriteMsg(). More...
void | SetFlags (wxSocketFlags flags)
| Use SetFlags to customize IO operation for this socket. More...
virtual bool | SetLocal (const wxIPV4address &local)
| Set the local address and port to use. More...
void | SetTimeout (long seconds)
| Set the default socket timeout in seconds. More...
wxSocketBase & | Unread (const void *buffer, wxUint32 nbytes)
| Put the specified data into the input queue. More...
bool | Wait (long seconds=-1, long millisecond=0)
| Wait for any socket event. More...
bool | WaitForLost (long seconds=-1, long millisecond=0)
| Wait until the connection is lost. More...
bool | WaitForRead (long seconds=-1, long millisecond=0)
| Wait until the socket is readable. More...
bool | WaitForWrite (long seconds=-1, long millisecond=0)
| Wait until the socket becomes writable. More...
wxSocketBase & | Write (const void *buffer, wxUint32 nbytes)
| Write up to the given number of bytes to the socket. More...
wxSocketBase & | WriteMsg (const void *buffer, wxUint32 nbytes)
| Sends a buffer which can be read using ReadMsg(). More...
void * | GetClientData () const
| Returns a pointer of the client data for this socket, as set with SetClientData() More...
void | Notify (bool notify)
| According to the notify value, this function enables or disables socket events. More...
void | SetClientData (void *data)
| Sets user-supplied client data for this socket. More...
void | SetEventHandler (wxEvtHandler &handler, int id=-1)
| Sets an event handler to be called when a socket event occurs. More...
void | SetNotify (wxSocketEventFlags flags)
| Specifies which socket events are to be sent to the event handler. More...
wxSOCKET_T | GetSocket () const
| Returns the native socket descriptor. More...
| wxSocketBase ()
| Default constructor. More...
virtual | ~wxSocketBase ()
| Destructor. More...
bool | Destroy ()
| Destroys the socket safely. More...
Public Member Functions inherited from wxObject
| wxObject ()
| Default ctor; initializes to NULL the internal reference data. More...
| wxObject (const wxObject &other)
| Copy ctor. More...
virtual | ~wxObject ()
| Destructor. More...
virtual wxClassInfo * | GetClassInfo () const
| This virtual function is redefined for every class that requires run-time type information, when using the wxDECLARE_CLASS macro (or similar). More...
wxObjectRefData * | GetRefData () const
| Returns the wxObject::m_refData pointer, i.e. the data referenced by this object. More...
bool | IsKindOf (const wxClassInfo *info) const
| Determines whether this class is a subclass of (or the same class as) the given class. More...
bool | IsSameAs (const wxObject &obj) const
| Returns true if this object has the same data pointer as obj. More...
void | Ref (const wxObject &clone)
| Makes this object refer to the data in clone. More...
void | SetRefData (wxObjectRefData *data)
| Sets the wxObject::m_refData pointer. More...
void | UnRef ()
| Decrements the reference count in the associated data, and if it is zero, deletes the data. More...
void | UnShare ()
| This is the same of AllocExclusive() but this method is public. More...
void | operator delete (void *buf)
| The delete operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...
void * | operator new (size_t size, const wxString &filename=NULL, int lineNum=0)
| The new operator is defined for debugging versions of the library only, when the identifier `__WXDEBUG__` is defined. More...

## Additional Inherited Members

Static Public Member Functions inherited from wxSocketBase
static bool | Initialize ()
| Perform the initialization needed in order to use the sockets. More...
static void | Shutdown ()
| Shut down the sockets. More...
Protected Member Functions inherited from wxObject
void | AllocExclusive ()
| Ensure that this object's data is not shared with any other object. More...
virtual wxObjectRefData * | CreateRefData () const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and returns it. More...
virtual wxObjectRefData * | CloneRefData (const wxObjectRefData *data) const
| Creates a new instance of the wxObjectRefData-derived class specific to this object and initializes it copying data. More...
Protected Attributes inherited from wxObject
wxObjectRefData * | m_refData
| Pointer to an object which is the object's reference-counted data. More...

## Constructor & Destructor Documentation

## ◆ 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, remember to test whether it succeeded with wxSocketBase:IsOk().

Parameters

  address | Specifies the local address for the server (e.g. port number).
  flags | Socket flags (See wxSocketBase::SetFlags()).

## ◆ ~wxSocketServer()

virtual wxSocketServer::~wxSocketServer | ( |  | ) |

virtual

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

## Member Function Documentation

## ◆ Accept()

wxSocketBase* wxSocketServer::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 method 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.

Returns
  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
  WaitForAccept(), wxSocketBase::SetNotify(), wxSocketBase::Notify(), AcceptWith()

## ◆ AcceptWith()

bool wxSocketServer::AcceptWith | ( | wxSocketBase & | socket,
|  | bool | wait = `true`
| ) |  |

Accept an incoming connection using the specified socket object.

Parameters

  socket | Socket to be initialized
  wait | See Accept() for more info.

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

See also
  WaitForAccept(), wxSocketBase::SetNotify(), wxSocketBase::Notify(), Accept()

## ◆ WaitForAccept()

bool wxSocketServer::WaitForAccept | ( | long | seconds = `-1`,
|  | long | millisecond = `0`
| ) |  |

Wait 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 | Number of seconds to wait. If -1, it will wait for the default timeout, as set with wxSocketBase::SetTimeout().
  millisecond | Number of milliseconds to wait.

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

See also
  Accept(), AcceptWith(), wxSocketBase::InterruptWait()