News SF.net Project Frequently Asked Questions Documentation Downloads Mailing Lists How to Contribute

SourceForge.net Logo

Changing the way games are made and played.

TNL::Socket class Reference

TNL::Socket Class Reference

#include <tnlUDP.h>


Detailed Description

The Socket class encapsulates a platform's network socket.


Public Types

enum  { DefaultBufferSize = 32768 }

Public Member Functions

 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.

NetError connect (const Address &theAddress)
NetError recv (U8 *buffer, S32 bufferSize, S32 *bytesRead)
NetError send (const U8 *buffer, S32 bufferSize)

Static Public Member Functions

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


Private Attributes

S32 mPlatformSocket
 The OS-level socket.

U32 mTransportProtocol
 The transport type this socket uses.


Member Enumeration Documentation

anonymous enum
 

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


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.

TNL::Socket::~Socket  ) 
 

Closes the socket.


Member Function Documentation

bool TNL::Socket::isValid  ) 
 

Returns true if the socket was created successfully.

NetError TNL::Socket::sendto const Address address,
const U8 buffer,
S32  bufferSize
 

Sends a packet to the address through sourceSocket.

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.

Address TNL::Socket::getBoundAddress  ) 
 

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

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::connect const Address theAddress  ) 
 

NetError TNL::Socket::recv U8 buffer,
S32  bufferSize,
S32 bytesRead
 

NetError TNL::Socket::send const U8 buffer,
S32  bufferSize
 


Field Documentation

S32 TNL::Socket::mPlatformSocket [private]
 

The OS-level socket.

U32 TNL::Socket::mTransportProtocol [private]
 

The transport type this socket uses.