Main Page   Class Hierarchy   Compound List   Compound Members  

ArSocket Class Reference

socket communication wrapper. More...

#include <ArSocket.h>

List of all members.

Public Methods

 ArSocket ()
 Constructor.

 ArSocket (const char *host, int port, Type type)
 Constructor which connects to a server. More...

 ArSocket (int port, bool doClose, Type type)
 Constructor which opens a server port. More...

 ~ArSocket ()
 Destructor.

bool copy (int fd, bool doclose)
 Copy socket structures. More...

void copy (ArSocket *s)
 Copy socket structures.

void transfer (ArSocket *s)
 Transfer ownership of a socket. More...

bool connect (const char *host, int port, Type type)
 Connect as a client to a server.

bool open (int port, Type type)
 Open a server port.

bool create (Type type)
 Simply create a port.

bool findValidPort (int startPort)
 Find a valid unused port and bind the socket to it.

bool connectTo (const char *host, int port)
 Connect the socket to the given address.

bool connectTo (struct sockaddr_in *sin)
 Connect the socket to the given address.

bool accept (ArSocket *sock)
 Accept a new connection.

bool close ()
 Close the socket.

int write (const void *buff, size_t len)
 Write to the socket. More...

int read (void *buff, size_t len, unsigned int msWait=0)
 Read from the socket. More...

int sendTo (const void *msg, int len)
 Send a message on the socket.

int sendTo (const void *msg, int len, struct sockaddr_in *sin)
 Send a message on the socket.

int recvFrom (void *msg, int len, sockaddr_in *sin)
 Receive a message from the socket.

bool getSockName ()
 Get the socket name. Stored in ArSocket::mySin.

sockaddr_in * sockAddrIn ()
 Accessor for the sockaddr.

in_addr * inAddr ()
 Accessor for the in_addr.

unsigned short int inPort ()
 Accessor for the port of the sockaddr.

bool setLinger (int time)
 Set the linger value.

bool setBroadcast ()
 Set broadcast value.

bool setReuseAddress ()
 Set the reuse address value.

bool setNonBlock ()
 Set socket to nonblocking.

void setDoClose (bool yesno)
 Change the doClose value.

int getFD () const
 Get the file descriptor.

Type getType () const
 Get the protocol type.

const std::string & getErrorStr () const
 Get the last error string.

Error getError () const
 Get the last error.

int writeString (const char *str,...)
 Writes a string to the socket. More...

bool readString (char *buf, size_t len)
 Reads a string from the socket. More...


Static Public Methods

bool init ()
 Initialize the network layer. More...

void shutdown ()
 Shutdown the network layer. More...

bool hostAddr (const char *host, struct in_addr &addr)
 Convert a host string to an address structure.

bool addrHost (struct in_addr &addr, char *host)
 Convert an address structure to a host string.

std::string getHostName ()
 Get the localhost address.

void inToA (struct in_addr *addr, char *buff)
 Convert addr into string numerical address.

const size_t sockAddrLen ()
 Size of the sockaddr.

const size_t maxHostNameLen ()
 Max host name length.

unsigned int hostToNetOrder (int i)
 Host byte order to network byte order.

unsigned int netToHostOrder (int i)
 Network byte order to host byte order.


Detailed Description

socket communication wrapper.

ArSocket is a layer which allows people to use the sockets networking interface in an operating system independent manner. All of the standard commonly used socket functions are implemented. This class also contains the file descriptor which identifies the socket to the operating system.

In Windows, the networking subsystem needs to be initialized and shutdown individyaly by each program. So when a program starts they will need to call the static function ArSocket::init() and call ArSocket::shutdown() when it exits. For programs that use Aria::init() and Aria::uninit() calling the ArSocket::init() and ArSocket::shutdown() is unnecessary. The Aria initialization functions take care of this. These functions do nothing in Linux.


Constructor & Destructor Documentation

ArSocket::ArSocket const char *    host,
int    port,
Type    type
 

Constructor which connects to a server.

Constructs the socket and connects it to the given host.

Parameters:
host  hostname of the server to connect to
port  port number of the server to connect to
type  protocol type to use

ArSocket::ArSocket int    port,
bool    doClose,
Type    type
 

Constructor which opens a server port.

Constructs the socket and opens it as a server port.

Parameters:
port  port number to bind the socket to
doClose  automaticaly close the port if the socket is destructed
type  protocol type to use


Member Function Documentation

bool ArSocket::copy int    fd,
bool    doclose
 

Copy socket structures.

Copy socket structures. Copy from one Socket to another will still have the first socket close the file descripter when it is destructed.

bool ArSocket::init void    [static]
 

Initialize the network layer.

In Windows, the networking subsystem needs to be initialized and shutdown individyaly by each program. So when a program starts they will need to call the static function ArSocket::init() and call ArSocket::shutdown() when it exits. For programs that use Aria::init() and Aria::uninit() calling the ArSocket::init() and ArSocket::shutdown() is unnecessary. The Aria initialization functions take care of this. These functions do nothing in Linux.

int ArSocket::read void *    buff,
size_t    len,
unsigned int    msWait = 0
[inline]
 

Read from the socket.

Parameters:
buff  buffer to read into
len  how many bytes to read
msWait  if 0, don't block, if > 0 wait this long for data
Returns:
number of bytes read

bool ArSocket::readString char *    buf,
size_t    len
[inline]
 

Reads a string from the socket.

Parameters:
buf  the buffer to read the string into, if there is no error but there is no string to read then the first character of the buffer is set to the null character
len  the lenth of the buffer
Returns:
true if the socket could be read from, false if it couldn't (which also means the connection should be closed)

void ArSocket::shutdown   [static]
 

Shutdown the network layer.

In Windows, the networking subsystem needs to be initialized and shutdown individyaly by each program. So when a program starts they will need to call the static function ArSocket::init() and call ArSocket::shutdown() when it exits. For programs that use Aria::init() and Aria::uninit() calling the ArSocket::init() and ArSocket::shutdown() is unnecessary. The Aria initialization functions take care of this. These functions do nothing in Linux.

void ArSocket::transfer ArSocket *    s [inline]
 

Transfer ownership of a socket.

transfer() will transfer ownership to this socket. The input socket will no longer close the file descriptor when it is destructed.

int ArSocket::write const void *    buff,
size_t    len
[inline]
 

Write to the socket.

Parameters:
buff  buffer to write from
len  how many bytes to write
Returns:
number of bytes written

int ArSocket::writeString const char *    str,
...   
[inline]
 

Writes a string to the socket.

This cannot write more than 2048 number of bytes

Parameters:
str  the string to write to the socket
Returns:
number of bytes written


The documentation for this class was generated from the following files:
Generated on Tue Nov 12 17:44:05 2002 for Aria by doxygen1.2.13.1 written by Dimitri van Heesch, © 1997-2001