Zen API

- Home
- Help Topics
- Types by Category
- All Types
- Files

All Classes Files Functions Variables Typedefs Macros Groups Pages
Public Member Functions
kUdpClient Class Reference
kApi/Io

## Description

Represents a UDP client.

Inheritance diagram for kUdpClient:

## Public Member Functions
kAlloc | kObject_Alloc (kObject object)
| Gets the memory allocator associated with this object. More...
kStatus | kObject_Clone (kObject *object, kObject source, kAlloc allocator)
| Constructs a new object by copying an existing object, including any aggregated child elements. More...
kStatus | kObject_Destroy (kObject object)
| Destroys the object. More...
kStatus | kObject_Dispose (kObject object)
| Destroys the object and any aggregated child elements. More...
kBool | kObject_Equals (kObject object, kObject other)
| Determines whether the object is equal to another object. More...
kSize | kObject_HashCode (kObject object)
| Gets a hash code representing the state of this object. More...
kBool | kObject_Is (kObject object, kType type)
| Determines whether this object is an instance of the specified type. More...
kBool | kObject_IsShared (kObject object)
| Reports whether the object is currently shared (reference count greater than one). More...
kStatus | kObject_SetPool (kObject object, kObjectPool pool)
| Sets the object pool associated with this object. More...
kStatus | kObject_Share (kObject object)
| Increments the reference count associated with this object. More...
kSize | kObject_Size (kObject object)
| Estimates the memory consumed by this object, including any aggregated child elements. More...
kType | kObject_Type (kObject object)
| Returns the type of the object. More...
k64u | kStream_BytesRead (kStream stream)
| Reports the number of bytes read from this stream. More...
k64u | kStream_BytesWritten (kStream stream)
| Reports the number of bytes written to this stream. More...
kStatus | kStream_ClearStats (kStream stream)
| Clears stream statistics (e.g. More...
kStatus | kStream_Copy (kStream stream, kStream source, kSize size)
| Copies the specified number of bytes from one stream to another. More...
kStatus | kStream_CopyEx (kStream stream, kStream source, kSize size, kCallbackFx progress, kPointer context)
| Copies the specified number of bytes from one stream to another, with progress feedback. More...
kStatus | kStream_Flush (kStream stream)
| Flushes buffered writes to the underlying medium. More...
kStatus | kStream_Read (kStream stream, void *buffer, kSize size)
| Reads the specified number of bytes from the stream. More...
kStatus | kStream_ReadSome (kStream stream, void *buffer, kSize minCount, kSize maxCount, kSize *bytesRead)
| Reads up to the specified number of bytes from the stream. More...
kStatus | kStream_Seek (kStream stream, k64s offset, kSeekOrigin origin)
| Moves the read/write pointer to the specified location. More...
kStatus | kStream_Write (kStream stream, const void *buffer, kSize size)
| Writes the specified number of bytes to the stream. More...
kStatus | kUdpClient_Bind (kUdpClient client, kIpAddress address, k32u port)
| Binds the client to a local IP address and/or port. More...
kStatus | kUdpClient_Clear (kUdpClient client)
| Clears the internal write buffer state. More...
kStatus | kUdpClient_Construct (kUdpClient *client, kIpVersion ipVersion, kAlloc allocator)
| Constructs a UDP client object. More...
kStatus | kUdpClient_EnableBroadcast (kUdpClient client, kBool broadcast)
| Enables or disables broadcasting. More...
kStatus | kUdpClient_EnableBroadcastReceive (kUdpClient client, kBool broadcast)
| Enables the ability to receive broadcast messages. More...
kStatus | kUdpClient_EnableReuseAddress (kUdpClient client, kBool reuse)
| Enables or disables reuse of a local end point within a short period of time. More...
kStatus | kUdpClient_LocalEndPoint (kUdpClient client, kIpEndPoint *endPoint)
| Returns the local end point for a bound client. More...
kStatus | kUdpClient_ReadFrom (kUdpClient client, kIpEndPoint *endPoint, void *buffer, kSize capacity, kSize *received, k64u timeout)
| Blocks until a datagram is received into the provided buffer (or until a timeout occurs). More...
kStatus | kUdpClient_Receive (kUdpClient client, kIpEndPoint *endPoint, kSize *received, k64u timeout)
| Blocks until a datagram is received into kUdpClient's read buffer (or until a timeout occurs). More...
kStatus | kUdpClient_Send (kUdpClient client, kIpAddress address, k32u port, k64u timeout, kBool clear)
| Blocks until the datagram in kUdpClient's internal write buffer is written to the underlying socket (or until a timeout occurs). More...
kStatus | kUdpClient_SetReadBuffers (kUdpClient client, kSSize socketSize, kSSize clientSize)
| Sets the size of read buffers. More...
kStatus | kUdpClient_SetWriteBuffers (kUdpClient client, kSSize socketSize, kSSize clientSize)
| Sets the size of write buffers. More...
kSocket | kUdpClient_Socket (kUdpClient client)
| Returns the underlying kSocket object. More...
kStatus | kUdpClient_WriteTo (kUdpClient client, const void *buffer, kSize size, kIpAddress address, k32u port, k64u timeout)
| Blocks until the provided datagram is written to the underlying socket (or until a timeout occurs). More...

## Member Function Documentation

kAlloc kObject_Alloc | ( | kObject | object | ) |
| inherited

Gets the memory allocator associated with this object.

Most objects are constructed with an allocator, which is used to allocate the memory required by the object. Objects retain a reference to this allocator to enable further allocations and to free memory when the object is destroyed.

Parameters

  object | Object.

Returns
  Memory allocator.

See also
  kAlloc, kObject_Alloc_

kStatus kObject_Clone | ( | kObject * | object,
|  | kObject | source,
|  | kAlloc | allocator
| ) |  |
| inherited

Constructs a new object by copying an existing object, including any aggregated child elements.

If the source object is an object collection (e.g. kArrayList<kString>), any aggregated child objects are also cloned. In this case, the kObject_Dispose method can be used to free the cloned collection and its associated elements.

This method will fail if the source object (or an aggregated child element) does not support cloning.

Parameters

  object | Receives the constructed object.
  source | Source object.
  allocator | Memory allocator (or kNULL for default).

Returns
  Operation status.

See also
  kObject_Dispose

kStatus kObject_Destroy | ( | kObject | object | ) |
| inherited

Destroys the object.

The kObject_Destroy method destroys the object itself and any resources that are owned by the object. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters

  object | Object (or kNULL).

Returns
  Operation status.

See also
  Object Destruction, Reference Counting

kStatus kObject_Dispose | ( | kObject | object | ) |
| inherited

Destroys the object and any aggregated child elements.

The kObject_Dispose method destroys the object itself, any resources that are owned by the object, and if the object represents a collection of objects, any child objects in the collection. See Object Destruction for more information.

When an object is destroyed (or disposed), its reference count is decremented. The object is only truly destroyed when the reference count reaches zero. See Reference Counting for more information.

Parameters

  object | Object (or kNULL).

Returns
  Operation status.

See also
  Object Destruction, Reference Counting

kBool kObject_Equals | ( | kObject | object,
|  | kObject | other
| ) |  |
| inherited

Determines whether the object is equal to another object.

By default, objects are compared by reference; objects are considered equal if the given handles refer to the same object instance. However, some classes override the Equals method to provide a more meaningful comparison (e.g. kString).

Parameters

  object | Object.
  other | Object for comparison.

Returns
  kTRUE if the objects are equal.

kSize kObject_HashCode | ( | kObject | object | ) |
| inherited

Gets a hash code representing the state of this object.

By default, objects return a hash code based on the object handle value. However, some classes override the HashCode method to provide a more useful hash (e.g. kString).

Parameters

  object | Object.

Returns
  Hash code.

kBool kObject_Is | ( | kObject | object,
|  | kType | type
| ) |  |
| inherited

Determines whether this object is an instance of the specified type.

This function compares the type of this object with the given type. An object is considered to be an instance of a given type if a) the type represents a class and this object inherits from (or instantiates) that class, or b) the type represents an interface and this object implements the interface.

Parameters

  object | Object.
  type | Type.

Returns
  kTRUE if the object is of the specified type; otherwise kFALSE.

See also
  kObject_Is_, kType_Is

kBool kObject_IsShared | ( | kObject | object | ) |
| inherited

Reports whether the object is currently shared (reference count greater than one).

Objects are initialized with a reference count of one. The kObject_Share method can be used to increment the reference count. The kObject_Destroy and kObject_Dispose methods decrease the reference count, and when the reference count reaches zero, the object is actually destroyed/disposed.

This method can be used to determine if the reference count of an object is currently greater than one.

This method is thread-safe.

Parameters

  object | Object.

Returns
  kTRUE if the object is shared; kFALSE otherwise.

See also
  Reference Counting, kObject_Share

kStatus kObject_SetPool | ( | kObject | object,
|  | kObjectPool | pool
| ) |  |
| inherited

Sets the object pool associated with this object.

Object pools can be used to implement custom lifecycle management. If an object has an assigned pool, then the kObjectPool_Reclaim method will be called just prior to destruction, to provide an opportunity for the object to be reclaimed.

Parameters

  object | Object.
  pool | Pool object (or kNULL to clear the pool assignment).

Returns
  Operation status.

kStatus kObject_Share | ( | kObject | object | ) |
| inherited

Increments the reference count associated with this object.

This method is thread-safe.

Parameters

  object | Object.

Returns
  Operation status.

See also
  reference-counting

kSize kObject_Size | ( | kObject | object | ) |
| inherited

Estimates the memory consumed by this object, including any aggregated child elements.

This method can be optionally overridden by kObject-derived classes to report the amount of memory consumed by an object. The default implementation reports only the size of the class instance (additional allocations performed by the class are excluded).

Parameters

  object | Object.

Returns
  Object size, in bytes.

kType kObject_Type | ( | kObject | object | ) |
| inherited

Returns the type of the object.

Each object is an instance of a specific class type. The type handle returned by this function can be used to learn about the class.

Parameters

  object | Object.

Returns
  Type.

See also
  kType, kObject_Type_

k64u kStream_BytesRead | ( | kStream | stream | ) |
| inherited

Reports the number of bytes read from this stream.

Parameters

  stream | Stream object.

Returns
  Count of bytes read.

k64u kStream_BytesWritten | ( | kStream | stream | ) |
| inherited

Reports the number of bytes written to this stream.

Parameters

  stream | Stream object.

Returns
  Count of bytes written.

kStatus kStream_ClearStats | ( | kStream | stream | ) |
| inherited

Clears stream statistics (e.g.

BytesRead, BytesWritten).

Parameters

  stream | Stream object.

Returns
  Operation Status

kStatus kStream_Copy | ( | kStream | stream,
|  | kStream | source,
|  | kSize | size
| ) |  |
| inherited

Copies the specified number of bytes from one stream to another.

Parameters

  stream | Destination stream.
  source | Source stream.
  size | Count of bytes to be copied.

Returns
  Operation status.

kStatus kStream_CopyEx | ( | kStream | stream,
|  | kStream | source,
|  | kSize | size,
|  | kCallbackFx | progress,
|  | kPointer | context
| ) |  |
| inherited

Copies the specified number of bytes from one stream to another, with progress feedback.

The specified callback will be invoked to provide feedback on the progress of the operation. The callback 'args' parameter will receive a k32u value representing the percentage completed. The callback is guaranteed to be called at least once if the operation is successful, with a progress value of 100%.

Parameters

  stream | Destination stream.
  source | Source stream.
  size | Count of bytes to be copied.
  progress | Optional progress callback (can be kNULL).
  context | Callback context.

Returns
  Operation status.

kStatus kStream_Flush | ( | kStream | stream | ) |
| inherited

Flushes buffered writes to the underlying medium.

Parameters

  stream | Stream object.

Returns
  Operation status.

kStatus kStream_Read | ( | kStream | stream,
|  | void * | buffer,
|  | kSize | size
| ) |  |
| inherited

Reads the specified number of bytes from the stream.

Parameters

  stream | Stream object.
  buffer | Destination for bytes that are read.
  size | Count of bytes to read.

Returns
  Operation status.

kStatus kStream_ReadSome | ( | kStream | stream,
|  | void * | buffer,
|  | kSize | minCount,
|  | kSize | maxCount,
|  | kSize * | bytesRead
| ) |  |
| inherited

Reads up to the specified number of bytes from the stream.

Parameters

  stream | Stream object.
  buffer | Destination for bytes that are read.
  minCount | Minimum count of bytes to read.
  maxCount | Maximum count of bytes to read.
  bytesRead | Receives count of bytes read.

Returns
  Operation status.

kStatus kStream_Seek | ( | kStream | stream,
|  | k64s | offset,
|  | kSeekOrigin | origin
| ) |  |
| inherited

Moves the read/write pointer to the specified location.

Parameters

  stream | Stream object.
  offset | Offset by which to adjust the read/write pointer.
  origin | Origin to which movement is relative (i.e. begin, current, end).

Returns
  Operation status.

kStatus kStream_Write | ( | kStream | stream,
|  | const void * | buffer,
|  | kSize | size
| ) |  |
| inherited

Writes the specified number of bytes to the stream.

Parameters

  stream | Stream object.
  buffer | Bytes to be written to the stream.
  size | Count of bytes to be written.

Returns
  Operation status.

kStatus kUdpClient_Bind | ( | kUdpClient | client,
|  | kIpAddress | address,
|  | k32u | port
| ) |  |

Binds the client to a local IP address and/or port.

Parameters

  client | UDP client object.
  address | A local IP address, or kIpAddress_Any().
  port | A local port number, or kIP_PORT_ANY.

Returns
  Operation status.

kStatus kUdpClient_Clear | ( | kUdpClient | client | ) |

Clears the internal write buffer state.

Parameters

  client | UDP client object.

Returns
  Operation status.

kStatus kUdpClient_Construct | ( | kUdpClient * | client,
|  | kIpVersion | ipVersion,
|  | kAlloc | allocator
| ) |  |

Constructs a UDP client object.

Parameters

  client | Destination for the constructed object handle.
  ipVersion | Internet Protocol version.
  allocator | Memory allocator (or kNULL for default).

Returns
  Operation status.

kStatus kUdpClient_EnableBroadcast | ( | kUdpClient | client,
|  | kBool | broadcast
| ) |  |

Enables or disables broadcasting.

If broadcasting is enabled, sending to kIpAddress_BroadcastV4() will broadcast a datagram on the subnet associated with the IPv4 address to which the client is bound.

Broadcasts are disabled by default.

Parameters

  client | UDP client object.
  broadcast | kTRUE to enable broadcasts; kFALSE otherwise.

Returns
  Operation status.

kStatus kUdpClient_EnableBroadcastReceive | ( | kUdpClient | client,
|  | kBool | broadcast
| ) |  |

Enables the ability to receive broadcast messages.

This function is required to work around a limitation in DSP/BIOS that prevents sockets from receiving broadcasts unless they are bound to kIpAddress_AnyV4(). When used, this function must be called before kUdpClient_Bind.

This function is harmless (no effect) when used on other operating systems.

Parameters

  client | UDP client object.
  broadcast | kTRUE to enable broadcasts; kFALSE otherwise.

Returns
  Operation status.

kStatus kUdpClient_EnableReuseAddress | ( | kUdpClient | client,
|  | kBool | reuse
| ) |  |

Enables or disables reuse of a local end point within a short period of time.

The option is typically used to allow a server to rebind to a local end point while a previous socket with the same local end point is in the TIME_WAIT state. This can be useful when a server must be stopped and started within a brief interval, but there is a small risk that packets with identical source/destination information could be misdirected to the new socket.

This option is disabled by default.

Parameters

  client | UDP client object.
  reuse | kTRUE to enable reuse of IP addresses; kFALSE otherwise.

Returns
  Operation status.

kStatus kUdpClient_LocalEndPoint | ( | kUdpClient | client,
|  | kIpEndPoint * | endPoint
| ) |  |

Returns the local end point for a bound client.

Parameters

  client | UDP client object.
  endPoint | Local end point.

Returns
  Socket object.

kStatus kUdpClient_ReadFrom | ( | kUdpClient | client,
|  | kIpEndPoint * | endPoint,
|  | void * | buffer,
|  | kSize | capacity,
|  | kSize * | received,
|  | k64u | timeout
| ) |  |

Blocks until a datagram is received into the provided buffer (or until a timeout occurs).

This method can be used when read buffering is disabled to read a datagram directly from the underlying socket.

Parameters

  client | UDP client object.
  endPoint | Receives the end point of the sender.
  buffer | Destination for received bytes.
  capacity | Maximum count of bytes to read.
  received | Receives the size of the received datagram.
  timeout | Timeout, in microseconds.

Returns
  Operation status.

kStatus kUdpClient_Receive | ( | kUdpClient | client,
|  | kIpEndPoint * | endPoint,
|  | kSize * | received,
|  | k64u | timeout
| ) |  |

Blocks until a datagram is received into kUdpClient's read buffer (or until a timeout occurs).

The Receive method is used to receive a datagram into kUdpClient's internal read buffer. Once the datagram has been received, the kStream_Read method can be used to read out the datagram.

Parameters

  client | UDP client object.
  endPoint | Receives the end point of the sender.
  received | Receives the size of the received datagram.
  timeout | Timeout, in microseconds.

Returns
  Operation status.

kStatus kUdpClient_Send | ( | kUdpClient | client,
|  | kIpAddress | address,
|  | k32u | port,
|  | k64u | timeout,
|  | kBool | clear
| ) |  |

Blocks until the datagram in kUdpClient's internal write buffer is written to the underlying socket (or until a timeout occurs).

The Send method is used to send a datagram that has been written into kUdpClient's internal write buffer. Bytes are written into kUdpClient's internal buffer via the kStream_Write method.

Optionally the internal write buffer is updated. User clear=kFALSE in case retransmission is needed.

Parameters

  client | UDP client object.
  address | IP address of the recipient.
  port | Port number of the recipient.
  timeout | Timeout, in microseconds.
  clear | Specifies whether the internal write buffer pointer is updated.

Returns
  Operation status.

kStatus kUdpClient_SetReadBuffers | ( | kUdpClient | client,
|  | kSSize | socketSize,
|  | kSSize | clientSize
| ) |  |

Sets the size of read buffers.

Socket buffers decouple the sender and receiver, so that the sender does not need to block while waiting for the receiver to receive all bytes. Client buffers enable the client to read the datagram over multiple read calls, rather than receiving the entire datagram in a single read call.

If the client buffer size is greater than zero, use the kUdpClient_Receive method to receive a datagram before calling kUdpClient_Read. If the client buffer size is zero, a complete datagram can be received (without buffering) using kUdpClient_ReadFrom.

Parameters

  client | UDP client object.
  socketSize | Size of the read buffer maintained by the underlying socket (-1 to leave unchanged).
  clientSize | Size of the read buffer maintained by the client object (-1 to leave unchanged).

Returns
  Operation status.

kStatus kUdpClient_SetWriteBuffers | ( | kUdpClient | client,
|  | kSSize | socketSize,
|  | kSSize | clientSize
| ) |  |

Sets the size of write buffers.

Socket buffers decouple the sender and receiver, so that the sender does not need to block while waiting for the receiver to receive all bytes. Client buffers enable the sender to formulate a datagram over multiple writes, rather than supplying the entire datagram in a single write call.

If the client buffer size is greater than zero, use the kUdpClient_Send method to send the datagram when writing is complete. If the client buffer size is zero, a datagram can be sent immediately (without buffering) using kUdpClient_WriteTo.

By default, the client buffer size is zero and the socket buffer size is determined by the underlying operating system.

Parameters

  client | UDP client object.
  socketSize | Size of the write buffer maintained by the underlying socket (-1 to leave unchanged).
  clientSize | Size of the write buffer maintained by the client object (-1 to leave unchanged).

Returns
  Operation status.

kSocket kUdpClient_Socket | ( | kUdpClient | client | ) |

Returns the underlying kSocket object.

Parameters

  client | UDP client object.

Returns
  Socket object.

kStatus kUdpClient_WriteTo | ( | kUdpClient | client,
|  | const void * | buffer,
|  | kSize | size,
|  | kIpAddress | address,
|  | k32u | port,
|  | k64u | timeout
| ) |  |

Blocks until the provided datagram is written to the underlying socket (or until a timeout occurs).

This method can be used when write buffering is disabled to write a datagram directly to the underlying socket.

Parameters

  client | UDP client object.
  buffer | Bytes to be written.
  size | Count of bytes to be written.
  address | IP address of the recipient.
  port | Port number of the recipient.
  timeout | Timeout, in microseconds.

Returns
  Operation status.

The documentation for this class was generated from the following file:

- Io/kUdpClient.h