CSL 5.2

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Static Public Member Functions | Protected Attributes | Private Member Functions
UDPSocket Class Reference

`#include <PracticalSocket.h>`

Inheritance diagram for UDPSocket:

List of all members.

## Public Member Functions
| UDPSocket () throw (SocketException)
| UDPSocket (unsigned short localPort) throw (SocketException)
| UDPSocket (const string &localAddress, unsigned short localPort) throw (SocketException)
void | disconnect () throw (SocketException)
void | sendTo (const void *buffer, int bufferLen, const string &foreignAddress, unsigned short foreignPort) throw (SocketException)
int | recvFrom (void *buffer, int bufferLen, string &sourceAddress, unsigned short &sourcePort) throw (SocketException)
void | setMulticastTTL (unsigned char multicastTTL) throw (SocketException)
void | joinGroup (const string &multicastGroup) throw (SocketException)
void | leaveGroup (const string &multicastGroup) throw (SocketException)
void | connect (const string &foreignAddress, unsigned short foreignPort) throw (SocketException)
void | send (const void *buffer, int bufferLen) throw (SocketException)
int | recv (void *buffer, int bufferLen) throw (SocketException)
string | getForeignAddress () throw (SocketException)
unsigned short | getForeignPort () throw (SocketException)
string | getLocalAddress () throw (SocketException)
unsigned short | getLocalPort () throw (SocketException)
void | setLocalPort (unsigned short localPort) throw (SocketException)
void | setLocalAddressAndPort (const string &localAddress, unsigned short localPort=0) throw (SocketException)

## Static Public Member Functions
static void | cleanUp () throw (SocketException)
static unsigned short | resolveService (const string &service, const string &protocol="tcp")

## Protected Attributes
int | sockDesc

## Private Member Functions
void | setBroadcast ()

## Detailed Description

UDP socket class

Definition at line 256 of file PracticalSocket.h.

## Constructor & Destructor Documentation

UDPSocket::UDPSocket | ( |  | ) | throw (SocketException)

Construct a UDP socket

Exceptions:

  SocketException | thrown if unable to create UDP socket

Definition at line 283 of file PracticalSocket.cpp.

References setBroadcast().

UDPSocket::UDPSocket | ( | unsigned short | localPort | ) | throw (SocketException)

Construct a UDP socket with the given local port

Parameters:

  localPort | local port

Exceptions:

  SocketException | thrown if unable to create UDP socket

Definition at line 288 of file PracticalSocket.cpp.

UDPSocket::UDPSocket | ( | const string & | localAddress,
|  | unsigned short | localPort
| ) |  | throw (SocketException)

Construct a UDP socket with the given local port and address

Parameters:

  localAddress | local address
  localPort | local port

Exceptions:

  SocketException | thrown if unable to create UDP socket

Definition at line 294 of file PracticalSocket.cpp.

## Member Function Documentation

void UDPSocket::disconnect | ( |  | ) | throw (SocketException)

Unset foreign address and port

Returns:
  true if disassociation is successful

Exceptions:

  SocketException | thrown if unable to disconnect UDP socket

Definition at line 308 of file PracticalSocket.cpp.

References CommunicatingSocket::connect(), and Socket::sockDesc.

void UDPSocket::sendTo | ( | const void * | buffer,
|  | int | bufferLen,
|  | const string & | foreignAddress,
|  | unsigned short | foreignPort
| ) |  | throw (SocketException)

Send the given buffer as a UDP datagram to the specified address/port

Parameters:

  buffer | buffer to be written
  bufferLen | number of bytes to write
  foreignAddress | address (IP address or name) to send to
  foreignPort | port number to send to

Returns:
  true if send is successful

Exceptions:

  SocketException | thrown if unable to send datagram

Definition at line 325 of file PracticalSocket.cpp.

References fillAddr(), and Socket::sockDesc.

Referenced by Controller::get_remote_data().

int UDPSocket::recvFrom | ( | void * | buffer,
|  | int | bufferLen,
|  | string & | sourceAddress,
|  | unsigned short & | sourcePort
| ) |  | throw (SocketException)

Read read up to bufferLen bytes data from this socket. The given buffer is where the data will be placed

Parameters:

  buffer | buffer to receive data
  bufferLen | maximum number of bytes to receive
  sourceAddress | address of datagram source
  sourcePort | port of data source

Returns:
  number of bytes received and -1 for error

Exceptions:

  SocketException | thrown if unable to receive datagram

Definition at line 338 of file PracticalSocket.cpp.

References Socket::sockDesc.

Referenced by Controller::get_remote_data().

void UDPSocket::setMulticastTTL | ( | unsigned char | multicastTTL | ) | throw (SocketException)

Set the multicast TTL

Parameters:

  multicastTTL | multicast TTL

Exceptions:

  SocketException | thrown if unable to set TTL

Definition at line 353 of file PracticalSocket.cpp.

References Socket::sockDesc.

void UDPSocket::joinGroup | ( | const string & | multicastGroup | ) | throw (SocketException)

Join the specified multicast group

Parameters:

  multicastGroup | multicast group address to join

Exceptions:

  SocketException | thrown if unable to join group

Definition at line 360 of file PracticalSocket.cpp.

References Socket::sockDesc.

void UDPSocket::leaveGroup | ( | const string & | multicastGroup | ) | throw (SocketException)

Leave the specified multicast group

Parameters:

  multicastGroup | multicast group address to leave

Exceptions:

  SocketException | thrown if unable to leave group

Definition at line 372 of file PracticalSocket.cpp.

References Socket::sockDesc.

void UDPSocket::setBroadcast | ( |  | ) |
| private

Definition at line 300 of file PracticalSocket.cpp.

References Socket::sockDesc.

Referenced by UDPSocket().

void CommunicatingSocket::connect | ( | const string & | foreignAddress,
|  | unsigned short | foreignPort
| ) |  | throw (SocketException)
| inherited

Attempt to establish a socket connection with the given foreign address and port

Parameters:

  foreignAddress | foreign address (IP address or name)
  foreignPort | foreign port

Returns:
  true if connection successfully established

Exceptions:

  SocketException | thrown if unable to establish connection

Definition at line 186 of file PracticalSocket.cpp.

References fillAddr().

Referenced by disconnect().

void CommunicatingSocket::send | ( | const void * | buffer,
|  | int | bufferLen
| ) |  | throw (SocketException)
| inherited

Write the given buffer to this socket. Call connect() before calling send()

Parameters:

  buffer | buffer to be written
  bufferLen | number of bytes from buffer to be written

Returns:
  true if the send is successful

Exceptions:

  SocketException | thrown if unable to send data

Definition at line 198 of file PracticalSocket.cpp.

int CommunicatingSocket::recv | ( | void * | buffer,
|  | int | bufferLen
| ) |  | throw (SocketException)
| inherited

Read into the given buffer up to bufferLen bytes data from this socket. Call connect() before calling recv()

Parameters:

  buffer | buffer to receive the data
  bufferLen | maximum number of bytes to read into buffer

Returns:
  number of bytes read, 0 for EOF, and -1 for error

Exceptions:

  SocketException | thrown if unable to receive data

Definition at line 205 of file PracticalSocket.cpp.

string CommunicatingSocket::getForeignAddress | ( |  | ) | throw (SocketException)
| inherited

Get the foreign address. Call connect() before calling recv()

Returns:
  foreign address

Exceptions:

  SocketException | thrown if unable to fetch foreign address

Definition at line 215 of file PracticalSocket.cpp.

References Socket::sockDesc.

unsigned short CommunicatingSocket::getForeignPort | ( |  | ) | throw (SocketException)
| inherited

Get the foreign port. Call connect() before calling recv()

Returns:
  foreign port

Exceptions:

  SocketException | thrown if unable to fetch foreign port

Definition at line 226 of file PracticalSocket.cpp.

References Socket::sockDesc.

string Socket::getLocalAddress | ( |  | ) | throw (SocketException)
| inherited

Get the local address

Returns:
  local address of socket

Exceptions:

  SocketException | thrown if fetch fails

Definition at line 115 of file PracticalSocket.cpp.

unsigned short Socket::getLocalPort | ( |  | ) | throw (SocketException)
| inherited

Get the local port

Returns:
  local port of socket

Exceptions:

  SocketException | thrown if fetch fails

Definition at line 125 of file PracticalSocket.cpp.

void Socket::setLocalPort | ( | unsigned short | localPort | ) | throw (SocketException)
| inherited

Set the local port to the specified port and the local address to any interface

Parameters:

  localPort | local port

Exceptions:

  SocketException | thrown if setting local port fails

Definition at line 135 of file PracticalSocket.cpp.

void Socket::setLocalAddressAndPort | ( | const string & | localAddress,
|  | unsigned short | localPort = `0`
| ) |  | throw (SocketException)
| inherited

Set the local port to the specified port and the local address to the specified address. If you omit the port, a random port will be selected.

Parameters:

  localAddress | local address
  localPort | local port

Exceptions:

  SocketException | thrown if setting local port or address fails

Definition at line 148 of file PracticalSocket.cpp.

References fillAddr().

void Socket::cleanUp | ( |  | ) | throw (SocketException)
| static inherited

If WinSock, unload the WinSock DLLs; otherwise do nothing. We ignore this in our sample client code but include it in the library for completeness. If you are running on Windows and you are concerned about DLL resource consumption, call this after you are done with all Socket instances. If you execute this on Windows while some instance of Socket exists, you are toast. For portability of client code, this is an empty function on non-Windows platforms so you can always include it.

Parameters:

  buffer | buffer to receive the data
  bufferLen | maximum number of bytes to read into buffer

Returns:
  number of bytes read, 0 for EOF, and -1 for error

Exceptions:

  SocketException | thrown WinSock clean up fails

Definition at line 159 of file PracticalSocket.cpp.

unsigned short Socket::resolveService | ( | const string & | service,
|  | const string & | protocol = `"tcp"`
| ) |  |
| static inherited

Resolve the specified service for the specified protocol to the corresponding port number in host byte order

Parameters:

  service | service to resolve (e.g., "http")
  protocol | protocol of service to resolve. Default is "tcp".

Definition at line 167 of file PracticalSocket.cpp.

## Member Data Documentation

int Socket::sockDesc
| protected inherited

Definition at line 126 of file PracticalSocket.h.

Referenced by TCPServerSocket::accept(), disconnect(), CommunicatingSocket::getForeignAddress(), CommunicatingSocket::getForeignPort(), joinGroup(), leaveGroup(), recvFrom(), sendTo(), setBroadcast(), and setMulticastTTL().

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

- CSL/Spatializers/VBAP/PracticalSocket.h
- CSL/Spatializers/VBAP/PracticalSocket.cpp