Main Page   Modules   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   Related Pages  

TNL::Socket Class Reference

The Socket class encapsulates a platform's network socket. More...

#include <tnlUDP.h>

List of all members.

Public Types

enum  { DefaultBufferSize = 32768 }

Public Methods

 Socket (const Address &bindAddress, U32 sendBufferSize=DefaultBufferSize, U32 recvBufferSize=DefaultBufferSize, bool acceptsBroadcast=true, bool nonblockingIO=true)
 Opens a socket on the specified address/port.

 ~Socket ()
 Closes the socket.

bool isValid ()
 Returns true if the socket was created successfully.

NetError sendto (const Address &address, const U8 *buffer, S32 bufferSize)
 Sends a packet to the address through sourceSocket.

NetError recvfrom (Address *address, U8 *buffer, S32 bufferSize, S32 *bytesRead)
 Read an incoming packet.

Address getBoundAddress ()
 Returns the Address corresponding to this socket, as bound on the local machine.


Static Public Methods

void getInterfaceAddresses (Vector< Address > *addressVector)
 Returns the list of network addresses this host can be bound to.


Detailed Description

The Socket class encapsulates a platform's network socket.

Definition at line 149 of file tnlUDP.h.


Member Enumeration Documentation

anonymous enum
 

Enumeration values:
DefaultBufferSize  The default send and receive buffer sizes.

Definition at line 154 of file tnlUDP.h.


Constructor & Destructor Documentation

TNL::Socket::Socket const Address   bindAddress,
U32    sendBufferSize = DefaultBufferSize,
U32    recvBufferSize = DefaultBufferSize,
bool    acceptsBroadcast = true,
bool    nonblockingIO = true
 

Opens a socket on the specified address/port.

A connectPort of 0 will bind to any available port. Passing a valid address for ipBindInterface will attempt to bind this socket to a particular IP address on the local machine.

Definition at line 207 of file udp.cpp.

References TNL::IPProtocol, TNL::IPXProtocol, TNL::TCPProtocol, TNL::Address::toString(), TNL::Address::transport, and TNL::U32.


Member Function Documentation

void TNL::Socket::getInterfaceAddresses Vector< Address > *    addressVector [static]
 

Returns the list of network addresses this host can be bound to.

Currently this only returns IP addresses, with the port field set to 0.

NetError TNL::Socket::recvfrom Address   address,
U8   buffer,
S32    bufferSize,
S32   bytesRead
 

Read an incoming packet.

Parameters:
address  Address originating the packet.
buffer  Buffer in to which to read the packet.
bufferSize  Size of the buffer (this prevents buffer overflows!).
bytesRead  Specifies the number of bytes which were actually in the packet.

Definition at line 347 of file udp.cpp.

References TNL::NetError, TNL::Address::netNum, TNL::NoError, TNL::Address::port, TNL::Address::transport, TNL::U8, and TNL::WouldBlock.

Referenced by TNL::PacketStream::recvfrom().


The documentation for this class was generated from the following files:
Generated on Thu Aug 18 16:03:37 2005 for Robin Hood: Thieves & Knights by doxygen1.2.18