as this correctly handles multi-homed hosts and avoids other small
problems. Internally, this is the same as setting the IP address
to @b INADDR_ANY.
as this correctly handles multi-homed hosts and avoids other small
problems. Internally, this is the same as setting the IP address
to @b INADDR_ANY.
- @seealso
- wxSocketServer::WaitForAccept, wxSocketBase::SetNotify, wxSocketBase::Notify,
- wxSocketServer::AcceptWith
+ @see wxSocketServer::WaitForAccept, wxSocketBase::SetNotify,
+ wxSocketBase::Notify, wxSocketServer::AcceptWith
Constructs a new server and tries to bind to the specified @e address.
Before trying to accept new connections, test whether it succeeded with
@ref wxSocketBase::isok wxSocketBase:IsOk.
Constructs a new server and tries to bind to the specified @e address.
Before trying to accept new connections, test whether it succeeded with
@ref wxSocketBase::isok wxSocketBase:IsOk.
*/
wxSocketServer(const wxSockAddress& address,
wxSocketFlags flags = wxSOCKET_NONE);
*/
wxSocketServer(const wxSockAddress& address,
wxSocketFlags flags = wxSOCKET_NONE);
Accepts an incoming connection request, and creates a new
wxSocketBase object which represents
the server-side of the connection.
Accepts an incoming connection request, and creates a new
wxSocketBase object which represents
the server-side of the connection.
accepted, it will wait for the next incoming connection to
arrive. @b Warning: This will block the GUI.
accepted, it will wait for the next incoming connection to
arrive. @b Warning: This will block the GUI.
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 @b wxSOCKET_CONNECTION events, then call Accept once you know
that there is an incoming connection waiting to be accepted.
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 @b 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.
-
- @sa WaitForAccept(), wxSocketBase::SetNotify,
- wxSocketBase::Notify, AcceptWith()
+
+ @return 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 WaitForAccept(), wxSocketBase::SetNotify,
+ wxSocketBase::Notify, AcceptWith()
- Socket to be initialized
-
- @returns Returns @true on success, or @false if an error occurred or if the
- wait parameter was @false and there were no pending
- connections.
+ Socket to be initialized
+
+ @return Returns @true on success, or @false if an error occurred or if the
+ wait parameter was @false and there were no pending
+ connections.
/**
This function waits for an incoming connection. Use it if you want to call
Accept() or AcceptWith()
with @e wait set to @false, to detect when an incoming connection is waiting
to be accepted.
/**
This function waits for an incoming connection. Use it if you want to call
Accept() or AcceptWith()
with @e wait set to @false, to detect when an incoming connection is waiting
to be accepted.
- Number of seconds to wait.
- If -1, it will wait for the default timeout,
- as set with SetTimeout.
-
+ Number of seconds to wait.
+ If -1, it will wait for the default timeout,
+ as set with SetTimeout.
- Number of milliseconds to wait.
-
- @returns Returns @true if an incoming connection arrived, @false if the
- timeout elapsed.
+ Number of milliseconds to wait.
+
+ @return Returns @true if an incoming connection arrived, @false if the
+ timeout elapsed.
*/
virtual bool AnyAddress();
/**
Internally, this is the same as setting the IP address
to @b INADDR_BROADCAST.
*/
virtual bool AnyAddress();
/**
Internally, this is the same as setting the IP address
to @b INADDR_BROADCAST.
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 @b wxSOCKET_CONNECTION events (for successful establishment)
and @b wxSOCKET_LOST events (for connection failure).
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 @b wxSOCKET_CONNECTION events (for successful establishment)
and @b wxSOCKET_LOST events (for connection failure).
- 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.
-
+ 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.
- If @true, waits for the connection to complete.
-
- @returns Returns @true if the connection is established and no error
- occurs.
-
- @sa WaitOnConnect(), wxSocketBase::SetNotify,
- wxSocketBase::Notify
- */
- bool Connect(wxSockAddress& address, bool wait = @true);
+ If @true, waits for the connection to complete.
+
+ @return Returns @true if the connection is established and no error
+ occurs.
+
+ @see WaitOnConnect(), wxSocketBase::SetNotify,
+ wxSocketBase::Notify
+ */
+ bool Connect(wxSockAddress& address, bool wait = true);
//@}
/**
Wait until a connection request completes, or until the specified timeout
elapses. Use this function after issuing a call
to Connect() with @e wait set to @false.
//@}
/**
Wait until a connection request completes, or until the specified timeout
elapses. Use this function after issuing a call
to Connect() with @e wait set to @false.
- Number of seconds to wait.
- If -1, it will wait for the default timeout,
- as set with SetTimeout.
-
+ Number of seconds to wait.
+ If -1, it will wait for the default timeout,
+ as set with SetTimeout.
- Number of milliseconds to wait.
-
- @returns 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.
+ Number of milliseconds to wait.
+
+ @return 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.
Gets the client data of the socket which generated this event, as
set with wxSocketBase::SetClientData.
*/
Gets the client data of the socket which generated this event, as
set with wxSocketBase::SetClientData.
*/
/**
Returns the socket object to which this event refers to. This makes
it possible to use the same event handler for different sockets.
*/
/**
Returns the socket object to which this event refers to. This makes
it possible to use the same event handler for different sockets.
*/
- @seealso
- wxSocketEvent, wxSocketClient, wxSocketServer, @ref overview_samplesockets
+ @see wxSocketEvent, wxSocketClient, wxSocketServer, @ref overview_samplesockets
the wxSocket to a list of object to be deleted on idle time, after all
events have been processed. For the same reason, you should avoid creating
socket objects in the stack.
the wxSocket to a list of object to be deleted on idle time, after all
events have been processed. For the same reason, you should avoid creating
socket objects in the stack.
*/
bool Destroy();
/**
This function simply deletes all bytes in the incoming queue. This function
always returns immediately and its operation is not affected by IO flags.
*/
bool Destroy();
/**
This function simply deletes all bytes in the incoming queue. This function
always returns immediately and its operation is not affected by IO flags.
If you use Error(), it will always return @false.
*/
wxSocketBase Discard();
/**
Returns @true if an error occurred in the last IO operation.
If you use Error(), it will always return @false.
*/
wxSocketBase Discard();
/**
Returns @true if an error occurred in the last IO operation.
Use this function to check for an error condition after one of the
following calls: Discard, Peek, Read, ReadMsg, Unread, Write, WriteMsg.
*/
Use this function to check for an error condition after one of the
following calls: Discard, Peek, Read, ReadMsg, Unread, Write, WriteMsg.
*/
/**
This function returns the local address field of the socket. The local
address field contains the complete local address of the socket (local
address, local port, ...).
/**
This function returns the local address field of the socket. The local
address field contains the complete local address of the socket (local
address, local port, ...).
/**
This function returns the peer address field of the socket. The peer
address field contains the complete peer host address of the socket
(address, port, ...).
/**
This function returns the peer address field of the socket. The peer
address field contains the complete peer host address of the socket
(address, port, ...).
some exception or abnormal problem. InterruptWait is automatically called
when you Close() a socket (and thus also upon
socket destruction), so you don't need to use it in these cases.
some exception or abnormal problem. InterruptWait is automatically called
when you Close() a socket (and thus also upon
socket destruction), so you don't need to use it in these cases.
immediately without blocking (unless the @b wxSOCKET_WAITALL flag
is set, in which case the operation might still block).
*/
immediately without blocking (unless the @b wxSOCKET_WAITALL flag
is set, in which case the operation might still block).
*/
Use this function to get the number of bytes actually transferred
after using one of the following IO calls: Discard, Peek, Read,
ReadMsg, Unread, Write, WriteMsg.
*/
Use this function to get the number of bytes actually transferred
after using one of the following IO calls: Discard, Peek, Read,
ReadMsg, Unread, Write, WriteMsg.
*/
Please note that this function merely returns the last error code,
but it should not be used to determine if an error has occurred (this
is because successful operations do not change the LastError value).
Please note that this function merely returns the last error code,
but it should not be used to determine if an error has occurred (this
is because successful operations do not change the LastError value).
if the last IO call failed. If this returns @true, use LastError
to discover the cause of the error.
*/
if the last IO call failed. If this returns @true, use LastError
to discover the cause of the error.
*/
- According to the @e notify value, this function enables
- or disables socket events. If @e notify is @true, the events
+ According to the @a notify value, this function enables
+ or disables socket events. If @a notify is @true, the events
- Number of bytes.
-
- @returns Returns a reference to the current object.
-
- @sa Error(), LastError(), LastCount(),
- SetFlags()
+ Number of bytes.
+
+ @return Returns a reference to the current object.
+
+ @see Error(), LastError(), LastCount(),
+ SetFlags()
- Number of bytes.
-
- @returns Returns a reference to the current object.
-
- @sa Error(), LastError(), LastCount(),
- SetFlags()
+ Number of bytes.
+
+ @return Returns a reference to the current object.
+
+ @see Error(), LastError(), LastCount(),
+ SetFlags()
/**
This function reads a buffer sent by WriteMsg()
on a socket. If the buffer passed to the function isn't big enough, the
remaining bytes will be discarded. This function always waits for the
buffer to be entirely filled, unless an error occurs.
/**
This function reads a buffer sent by WriteMsg()
on a socket. If the buffer passed to the function isn't big enough, the
remaining bytes will be discarded. This function always waits for the
buffer to be entirely filled, unless an error occurs.
- Size of the buffer.
-
- @returns Returns a reference to the current object.
-
- @sa Error(), LastError(), LastCount(),
- SetFlags(), WriteMsg()
+ Size of the buffer.
+
+ @return Returns a reference to the current object.
+
+ @see Error(), LastError(), LastCount(),
+ SetFlags(), WriteMsg()
event mask, as set with SetNotify() and
Notify(), user data, as set with
SetClientData().
event mask, as set with SetNotify() and
Notify(), user data, as set with
SetClientData().
contain a pointer to this data, which can be retrieved with
the wxSocketEvent::GetClientData function.
*/
contain a pointer to this data, which can be retrieved with
the wxSocketEvent::GetClientData function.
*/
/**
Sets an event handler to be called when a socket event occurs. The
handler will be called for those events for which notification is
enabled with SetNotify() and
Notify().
/**
Sets an event handler to be called when a socket event occurs. The
handler will be called for those events for which notification is
enabled with SetNotify() and
Notify().
- The id of socket event.
-
- @sa SetNotify(), Notify(), wxSocketEvent, wxEvtHandler
+ The id of socket event.
+
+ @see SetNotify(), Notify(), wxSocketEvent, wxEvtHandler
*/
void SetEventHandler(wxEvtHandler& handler, int id = -1);
/**
Use SetFlags to customize IO operation for this socket.
*/
void SetEventHandler(wxEvtHandler& handler, int id = -1);
/**
Use SetFlags to customize IO operation for this socket.
Stops the socket from being bound to a specific adapter (normally used in
conjunction with @b wxSOCKET_BROADCAST)
Stops the socket from being bound to a specific adapter (normally used in
conjunction with @b wxSOCKET_BROADCAST)
If no flag is specified (this is the same as @b wxSOCKET_NONE),
IO calls will return after some data has been read or written, even
when the transfer might not be complete. This is the same as issuing
exactly one blocking low-level call to recv() or send(). Note
that @e blocking here refers to when the function returns, not
to whether the GUI blocks during this time.
If no flag is specified (this is the same as @b wxSOCKET_NONE),
IO calls will return after some data has been read or written, even
when the transfer might not be complete. This is the same as issuing
exactly one blocking low-level call to recv() or send(). Note
that @e blocking here refers to when the function returns, not
to whether the GUI blocks during this time.
If @b wxSOCKET_NOWAIT is specified, IO calls will return immediately.
Read operations will retrieve only available data. Write operations will
write as much data as possible, depending on how much space is available
If @b wxSOCKET_NOWAIT is specified, IO calls will return immediately.
Read operations will retrieve only available data. Write operations will
write as much data as possible, depending on how much space is available
low-level call to recv() or send(). Note that @e nonblocking here
refers to when the function returns, not to whether the GUI blocks during
this time.
low-level call to recv() or send(). Note that @e nonblocking here
refers to when the function returns, not to whether the GUI blocks during
this time.
If @b wxSOCKET_WAITALL is specified, IO calls won't return until ALL
the data has been read or written (or until an error occurs), blocking if
necessary, and issuing several low level calls if necessary. This is the
If @b wxSOCKET_WAITALL is specified, IO calls won't return until ALL
the data has been read or written (or until an error occurs), blocking if
necessary, and issuing several low level calls if necessary. This is the
recv() or send() as needed so as to transfer all the data. Note
that @e blocking here refers to when the function returns, not
to whether the GUI blocks during this time.
recv() or send() as needed so as to transfer all the data. Note
that @e blocking here refers to when the function returns, not
to whether the GUI blocks during this time.
The @b wxSOCKET_BLOCK flag controls whether the GUI blocks during
IO operations. If this flag is specified, the socket will not yield
during IO calls, so the GUI will remain blocked until the operation
completes. If it is not used, then the application must take extra
care to avoid unwanted reentrance.
The @b wxSOCKET_BLOCK flag controls whether the GUI blocks during
IO operations. If this flag is specified, the socket will not yield
during IO calls, so the GUI will remain blocked until the operation
completes. If it is not used, then the application must take extra
care to avoid unwanted reentrance.
The @b wxSOCKET_REUSEADDR flag controls the use of the SO_REUSEADDR standard
setsockopt() flag. This flag allows the socket to bind to a port that is
already in use.
The @b wxSOCKET_REUSEADDR flag controls the use of the SO_REUSEADDR standard
setsockopt() flag. This flag allows the socket to bind to a port that is
already in use.
The @b wxSOCKET_BROADCAST flag controls the use of the SO_BROADCAST standard
setsockopt() flag. This flag allows the socket to use the broadcast address,
and is generally
used in conjunction with @b wxSOCKET_NOBIND and wxIPaddress::BroadcastAddress.
The @b wxSOCKET_BROADCAST flag controls the use of the SO_BROADCAST standard
setsockopt() flag. This flag allows the socket to use the broadcast address,
and is generally
used in conjunction with @b wxSOCKET_NOBIND and wxIPaddress::BroadcastAddress.
In this example, the user will be notified about incoming socket data and
whenever the connection is closed.
In this example, the user will be notified about incoming socket data and
whenever the connection is closed.
/**
This function unreads a buffer. That is, the data in the buffer is put back
in the incoming queue. This function is not affected by wxSocket flags.
/**
This function unreads a buffer. That is, the data in the buffer is put back
in the incoming queue. This function is not affected by wxSocket flags.
- Number of bytes.
-
- @returns Returns a reference to the current object.
-
- @sa Error(), LastCount(), LastError()
+ Number of bytes.
+
+ @return Returns a reference to the current object.
+
+ @see Error(), LastCount(), LastError()
The socket becomes readable.
The socket becomes writable.
An ongoing connection request has completed (wxSocketClient only)
An incoming connection request has arrived (wxSocketServer only)
The connection has been closed.
The socket becomes readable.
The socket becomes writable.
An ongoing connection request has completed (wxSocketClient only)
An incoming connection request has arrived (wxSocketServer only)
The connection has been closed.
Note that it is recommended to use the individual Wait functions
to wait for the required condition, instead of this one.
Note that it is recommended to use the individual Wait functions
to wait for the required condition, instead of this one.
- Number of seconds to wait.
- If -1, it will wait for the default timeout,
- as set with SetTimeout.
-
+ Number of seconds to wait.
+ If -1, it will wait for the default timeout,
+ as set with SetTimeout.
- Number of milliseconds to wait.
-
- @returns Returns @true when any of the above conditions is satisfied,
- @false if the timeout was reached.
-
- @sa InterruptWait(), wxSocketServer::WaitForAccept,
- WaitForLost(), WaitForRead(),
- WaitForWrite(), wxSocketClient::WaitOnConnect
+ Number of milliseconds to wait.
+
+ @return Returns @true when any of the above conditions is satisfied,
+ @false if the timeout was reached.
+
+ @see InterruptWait(), wxSocketServer::WaitForAccept,
+ WaitForLost(), WaitForRead(),
+ WaitForWrite(), wxSocketClient::WaitOnConnect
*/
bool Wait(long seconds = -1, long millisecond = 0);
/**
This function waits until the connection is lost. This may happen if
the peer gracefully closes the connection or if the connection breaks.
*/
bool Wait(long seconds = -1, long millisecond = 0);
/**
This function waits until the connection is lost. This may happen if
the peer gracefully closes the connection or if the connection breaks.
- Number of seconds to wait.
- If -1, it will wait for the default timeout,
- as set with SetTimeout.
-
+ Number of seconds to wait.
+ If -1, it will wait for the default timeout,
+ as set with SetTimeout.
- Number of milliseconds to wait.
-
- @returns Returns @true if the connection was lost, @false if the timeout
- was reached.
-
- @sa InterruptWait(), Wait()
+ Number of milliseconds to wait.
+
+ @return Returns @true if the connection was lost, @false if the timeout
+ was reached.
+
+ @see InterruptWait(), Wait()
the connection has been closed, so that a read operation will complete
immediately without blocking (unless the @b wxSOCKET_WAITALL flag
is set, in which case the operation might still block).
the connection has been closed, so that a read operation will complete
immediately without blocking (unless the @b wxSOCKET_WAITALL flag
is set, in which case the operation might still block).
- Number of seconds to wait.
- If -1, it will wait for the default timeout,
- as set with SetTimeout.
-
+ Number of seconds to wait.
+ If -1, it will wait for the default timeout,
+ as set with SetTimeout.
- Number of milliseconds to wait.
-
- @returns Returns @true if the socket becomes readable, @false on timeout.
-
- @sa InterruptWait(), Wait()
+ Number of milliseconds to wait.
+
+ @return Returns @true if the socket becomes readable, @false on timeout.
+
+ @see InterruptWait(), Wait()
connection has been closed, so that a write operation is guaranteed to
complete immediately (unless the @b wxSOCKET_WAITALL flag is set,
in which case the operation might still block).
connection has been closed, so that a write operation is guaranteed to
complete immediately (unless the @b wxSOCKET_WAITALL flag is set,
in which case the operation might still block).
- Number of seconds to wait.
- If -1, it will wait for the default timeout,
- as set with SetTimeout.
-
+ Number of seconds to wait.
+ If -1, it will wait for the default timeout,
+ as set with SetTimeout.
- Number of milliseconds to wait.
-
- @returns Returns @true if the socket becomes writable, @false on timeout.
-
- @sa InterruptWait(), Wait()
+ Number of milliseconds to wait.
+
+ @return Returns @true if the socket becomes writable, @false on timeout.
+
+ @see InterruptWait(), Wait()
- Number of bytes.
-
- @returns Returns a reference to the current object.
-
- @sa Error(), LastError(), LastCount(),
- SetFlags()
+ Number of bytes.
+
+ @return Returns a reference to the current object.
+
+ @see Error(), LastError(), LastCount(),
+ SetFlags()
writes a short header before so that ReadMsg()
knows how much data should it actually read. So, a buffer sent with WriteMsg
@b must be read with ReadMsg. This function always waits for the entire
buffer to be sent, unless an error occurs.
writes a short header before so that ReadMsg()
knows how much data should it actually read. So, a buffer sent with WriteMsg
@b must be read with ReadMsg. This function always waits for the entire
buffer to be sent, unless an error occurs.
- @seealso
- wxSocketBase::Error, wxSocketBase::LastError, wxSocketBase::LastCount,
+ @see wxSocketBase::Error, wxSocketBase::LastError, wxSocketBase::LastCount,
- Number of bytes.
-
- @returns Returns a reference to the current object, and the address of
- the peer that sent the data on address param.
-
- @sa wxSocketBase::Error, wxSocketBase::LastError, wxSocketBase::LastCount,
- wxSocketBase::SetFlags,
+ Number of bytes.
+
+ @return Returns a reference to the current object, and the address of
+ the peer that sent the data on address param.
+
+ @see wxSocketBase::Error, wxSocketBase::LastError, wxSocketBase::LastCount,
+ wxSocketBase::SetFlags,