#include <wx/socket.h>

The following event handler macros redirect the events to member function handlers 'func' with prototypes like:
Public Member Functions | |
Construction and Destruction | |
| wxSocketBase () | |
| ~wxSocketBase () | |
| bool | Destroy () |
Socket State | |
| bool | Error () const |
| bool | GetLocal (wxSockAddress &addr) const |
| bool | GetPeer (wxSockAddress &addr) const |
| long | GetTimeout () const |
| bool | IsConnected () const |
| bool | IsData () const |
| bool | IsDisconnected () const |
| bool | IsOk () const |
| wxUint32 | LastCount () const |
| wxSocketError | LastError () const |
| void | RestoreState () |
| void | SaveState () |
Basic I/O | |
| void | Close () |
| wxSocketBase | Discard () |
| wxSocketFlags | GetFlags () const |
| void | InterruptWait () |
| wxSocketBase | Peek (void *buffer, wxUint32 nbytes) |
| wxSocketBase | Read (void *buffer, wxUint32 nbytes) |
| wxSocketBase | ReadMsg (void *buffer, wxUint32 nbytes) |
| void | SetFlags (wxSocketFlags flags) |
| bool | SetLocal (const wxIPV4address &local) |
| void | SetTimeout (int seconds) |
| wxSocketBase | Unread (const void *buffer, wxUint32 nbytes) |
| bool | Wait (long seconds=-1, long millisecond=0) |
| bool | WaitForLost (long seconds=-1, long millisecond=0) |
| bool | WaitForRead (long seconds=-1, long millisecond=0) |
| bool | WaitForWrite (long seconds=-1, long millisecond=0) |
| wxSocketBase | Write (const void *buffer, wxUint32 nbytes) |
| wxSocketBase | WriteMsg (const void *buffer, wxUint32 nbytes) |
Handling Socket Events | |
| void * | GetClientData () const |
| void | Notify (bool notify) |
| void | SetClientData (void *data) |
| void | SetEventHandler (wxEvtHandler &handler, int id=-1) |
| void | SetNotify (wxSocketEventFlags flags) |
| wxSocketBase::wxSocketBase | ( | ) |
Default constructor.
Don't use it directly; instead, use wxSocketClient to construct a socket client, or wxSocketServer to construct a socket server.
| wxSocketBase::~wxSocketBase | ( | ) |
Destructor.
Do not destroy a socket using the delete operator directly; use Destroy() instead. Also, do not create socket objects in the stack.
| bool wxSocketBase::Destroy | ( | ) |
Destroys the socket safely.
Use this function instead of the delete operator, since otherwise socket events could reach the application even after the socket has been destroyed. To prevent this problem, this function appends 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.
Destroy() calls Close() automatically.
| bool wxSocketBase::Error | ( | ) | const |
| bool wxSocketBase::GetLocal | ( | wxSockAddress & | addr | ) | const |
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, ...).
| bool wxSocketBase::GetPeer | ( | wxSockAddress & | addr | ) | const |
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, ...).
| long wxSocketBase::GetTimeout | ( | ) | const |
Return the socket timeout in seconds.
The timeout can be set using SetTimeout() and is 10 minutes by default.
| bool wxSocketBase::IsConnected | ( | ) | const |
Returns true if the socket is connected.
| bool wxSocketBase::IsData | ( | ) | const |
This function waits until the socket is readable.
This might mean that queued data is available for reading or, for streamed sockets, that the connection has been closed, so that a read operation will complete immediately without blocking (unless the wxSOCKET_WAITALL flag is set, in which case the operation might still block).
| bool wxSocketBase::IsDisconnected | ( | ) | const |
Returns true if the socket is not connected.
| bool wxSocketBase::IsOk | ( | ) | const |
Returns true if the socket is initialized and ready and false in other cases.
| wxUint32 wxSocketBase::LastCount | ( | ) | const |
| wxSocketError wxSocketBase::LastError | ( | ) | const |
Returns the last wxSocket error. See wxSocketError .
| void wxSocketBase::RestoreState | ( | ) |
This function restores the previous state of the socket, as saved with SaveState().
Calls to SaveState() and RestoreState() can be nested.
| void wxSocketBase::SaveState | ( | ) |
This function saves the current state of the socket in a stack. Socket state includes flags, as set with SetFlags(), event mask, as set with SetNotify() and Notify(), user data, as set with SetClientData(). Calls to SaveState and RestoreState can be nested.
| void wxSocketBase::Close | ( | ) |
This function shuts down the socket, disabling further transmission and reception of data; it also disables events for the socket and frees the associated system resources.
Upon socket destruction, Close() is automatically called, so in most cases you won't need to do it yourself, unless you explicitly want to shut down the socket, typically to notify the peer that you are closing the connection.
| wxSocketBase wxSocketBase::Discard | ( | ) |
This function simply deletes all bytes in the incoming queue. This function always returns immediately and its operation is not affected by IO flags.
Use LastCount() to verify the number of bytes actually discarded.
If you use Error(), it will always return false.
| wxSocketFlags wxSocketBase::GetFlags | ( | ) | const |
Returns current IO flags, as set with SetFlags()
| void wxSocketBase::InterruptWait | ( | ) |
Use this function to interrupt any wait operation currently in progress.
Note that this is not intended as a regular way to interrupt a Wait call, but only as an escape mechanism for exceptional situations where it is absolutely necessary to use it, for example to abort an operation due to 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.
| wxSocketBase wxSocketBase::Peek | ( | void * | buffer, | |
| wxUint32 | nbytes | |||
| ) |
This function peeks a buffer of nbytes bytes from the socket.
Peeking a buffer doesn't delete it from the socket input queue.
Use LastCount() to verify the number of bytes actually peeked.
Use Error() to determine if the operation succeeded.
| buffer | Buffer where to put peeked data. | |
| nbytes | Number of bytes. |
| wxSocketBase wxSocketBase::Read | ( | void * | buffer, | |
| wxUint32 | nbytes | |||
| ) |
This function reads a buffer of nbytes bytes from the socket. Use LastCount() to verify the number of bytes actually read. Use Error() to determine if the operation succeeded.
| buffer | Buffer where to put read data. | |
| nbytes | Number of bytes. |
| wxSocketBase wxSocketBase::ReadMsg | ( | void * | buffer, | |
| wxUint32 | nbytes | |||
| ) |
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.
Use LastCount() to verify the number of bytes actually read.
Use Error() to determine if the operation succeeded.
| buffer | Buffer where to put read data. | |
| nbytes | Size of the buffer. |
| void wxSocketBase::SetFlags | ( | wxSocketFlags | flags | ) |
Use SetFlags to customize IO operation for this socket. The flags parameter may be a combination of flags ORed together. The following flags can be used:
| bool wxSocketBase::SetLocal | ( | const wxIPV4address & | local | ) |
This function allows you to set the local address and port, useful when an application needs to reuse a particular port. When a local port is set for a wxSocketClient, bind() will be called before connect().
| void wxSocketBase::SetTimeout | ( | int | seconds | ) |
This function sets the default socket timeout in seconds. This timeout applies to all IO calls, and also to the Wait() family of functions if you don't specify a wait interval. Initially, the default timeout is 10 minutes.
| wxSocketBase wxSocketBase::Unread | ( | const void * | buffer, | |
| wxUint32 | nbytes | |||
| ) |
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.
If you use LastCount(), it will always return nbytes.
If you use Error(), it will always return false.
| buffer | Buffer to be unread. | |
| nbytes | Number of bytes. |
| bool wxSocketBase::Wait | ( | long | seconds = -1, |
|
| long | millisecond = 0 | |||
| ) |
This function waits until any of the following conditions is true:
| seconds | Number of seconds to wait. If -1, it will wait for the default timeout, as set with SetTimeout(). | |
| millisecond | Number of milliseconds to wait. |
| bool wxSocketBase::WaitForLost | ( | 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.
| seconds | Number of seconds to wait. If -1, it will wait for the default timeout, as set with SetTimeout(). | |
| millisecond | Number of milliseconds to wait. |
| bool wxSocketBase::WaitForRead | ( | long | seconds = -1, |
|
| long | millisecond = 0 | |||
| ) |
This function waits until the socket is readable.
This might mean that queued data is available for reading or, for streamed sockets, that the connection has been closed, so that a read operation will complete immediately without blocking (unless the wxSOCKET_WAITALL flag is set, in which case the operation might still block).
| seconds | Number of seconds to wait. If -1, it will wait for the default timeout, as set with SetTimeout(). | |
| millisecond | Number of milliseconds to wait. |
| bool wxSocketBase::WaitForWrite | ( | long | seconds = -1, |
|
| long | millisecond = 0 | |||
| ) |
This function waits until the socket becomes writable.
This might mean that the socket is ready to send new data, or for streamed sockets, that the connection has been closed, so that a write operation is guaranteed to complete immediately (unless the wxSOCKET_WAITALL flag is set, in which case the operation might still block).
| seconds | Number of seconds to wait. If -1, it will wait for the default timeout, as set with SetTimeout(). | |
| millisecond | Number of milliseconds to wait. |
| wxSocketBase wxSocketBase::Write | ( | const void * | buffer, | |
| wxUint32 | nbytes | |||
| ) |
This function writes a buffer of nbytes bytes to the socket.
Use LastCount() to verify the number of bytes actually written.
Use Error() to determine if the operation succeeded.
| buffer | Buffer with the data to be sent. | |
| nbytes | Number of bytes. |
| wxSocketBase wxSocketBase::WriteMsg | ( | const void * | buffer, | |
| wxUint32 | nbytes | |||
| ) |
This function writes a buffer of nbytes bytes from the socket, but it writes a short header before so that ReadMsg() knows how much data should it actually read. So, a buffer sent with WriteMsg() MUST be read with ReadMsg().
This function always waits for the entire buffer to be sent, unless an error occurs.
Use LastCount() to verify the number of bytes actually written.
Use Error() to determine if the operation succeeded.
| buffer | Buffer with the data to be sent. | |
| nbytes | Number of bytes to send. |
| void* wxSocketBase::GetClientData | ( | ) | const |
Returns a pointer of the client data for this socket, as set with SetClientData()
| void wxSocketBase::Notify | ( | bool | notify | ) |
According to the notify value, this function enables or disables socket events. If notify is true, the events configured with SetNotify() will be sent to the application. If notify is false; no events will be sent.
| void wxSocketBase::SetClientData | ( | void * | data | ) |
Sets user-supplied client data for this socket. All socket events will contain a pointer to this data, which can be retrieved with the wxSocketEvent::GetClientData() function.
| void wxSocketBase::SetEventHandler | ( | wxEvtHandler & | handler, | |
| int | id = -1 | |||
| ) |
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().
| handler | Specifies the event handler you want to use. | |
| id | The id of socket event. |
| void wxSocketBase::SetNotify | ( | wxSocketEventFlags | flags | ) |
Specifies which socket events are to be sent to the event handler. The flags parameter may be combination of flags ORed together. The following flags can be used:
sock.SetNotify(wxSOCKET_INPUT_FLAG | wxSOCKET_LOST_FLAG);
sock.Notify(true);
In this example, the user will be notified about incoming socket data and whenever the connection is closed.
For more information on socket events see wxSocketEventFlags .
|
[ top ] |