Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields  

clawsoft::Socket Class Reference

#include <Socket.h>

Inheritance diagram for clawsoft::Socket:

Inheritance graph
[legend]
Collaboration diagram for clawsoft::Socket:

Collaboration graph
[legend]

Detailed Description

This class provides all the functionality for working with TCP sockets
NOTE: This socket interface is not backward compatible with previous versions of the clawlib library, sorry but all the old interfaces were to redundant and for sanity we took the desicion to upgrade the class this way.


Public Methods

 Socket ()
 This is a default constructor that does nothing.

 Socket (const char *thehost, int theport)
 This constructor tekas as an argument the host location as an IP number or as a name, also the port to connect to, take in count that in the very moment that this class is instantiated the socket would try to connect with thw remote host inmediately.

 Socket (TCPsocket s, int pport)
 This constructor takes as an argument the file descriptor defined for an already opened socket, the main idea is that you can use it in a subclass so you can have the same functionality ypu do when you use the other constructors.

 Socket (const Socket &s)
 This is a copy constructor.

 ~Socket ()
 This destructor does nothing.

void close (void)
 Closes the communications channel with the remote host inmmediately.

const int getPort ()
 Returns the port associated with this socket.

Socket & operator<< (const char chr)
 Sends a char to the other host.

Socket & operator<< (const int value)
 Sends an integer quantity to the remote host.

Socket & operator<< (const unsigned int value)
 Sends an unsigned integer quantity to the remote host.

Socket & operator<< (const float value)
 Sends a floating point value to the remote host.

Socket & operator<< (const double value)
 Sends a double presicion value to the remote host.

Socket & operator<< (const long double value)
 Sends a 96bit floating point value to the remote host.

Socket & operator<< (const long value)
 Sends a long(32bit) quantity to the remote host.

Socket & operator<< (const unsigned long value)
 Sends an unsigned long(32bit) quantity to the remote host.

Socket & operator<< (const Uint64 value)
 Sends a 64bit unsigned quantity to the remote host.

Socket & operator<< (String &str)
 Sends a string to the remote host THIS IS NOT A THREAD SAFE FUNCTION!!!!!

Socket & operator<< (const char *str)
 Sends a string to the remote host.

void write (const void *buffer, unsigned long size)
 Use this method when you need to send a fixed lenght buffer of bytes to the remote host, the routine will cut the buffer in chunks so the transfer can be safelly completed without out of memory error that might be caused if you attempt to send a very big buffer of data.

Socket & operator>> (char &chr)
 PLEASE RECONSIDER THE USE OF SDL_Net YOU SHOULD START USING ANOTHER OS INDEPENDENT NETWORK LIBRARY.

Socket & operator>> (int &value)
 Receives an integer quantity from the remote host.

Socket & operator>> (unsigned int &value)
 Receives an unsigned integer quantity from the remote host.

Socket & operator>> (float &value)
 Receives a floating point value from the remote host.

Socket & operator>> (double &value)
 Receives a double presicion value from the remote host.

Socket & operator>> (long double &value)
 Receives a 96bit floating point value from the remote host.

Socket & operator>> (long &value)
 Receives a long(32bit) quantity from the remote host.

Socket & operator>> (unsigned long &value)
 Receives an unsigned long(32bit) quantity from the remote host.

Socket & operator>> (Uint64 &value)
 Receives a 64bit unsigned quantity from the remote host.

Socket & operator>> (String &str)
 Receives a string from the remote host.

void read (void *buffer, unsigned long size)
 Use this method when you need to receive a fixed lenght buffer of bytes from the remote host, the routine will cut the buffer in chunks so the transfer can be safelly completed without out of memory error that might be caused if you attempt to receive a very big buffer of data.

const TCPsocket getSocket ()
 Returns the socket's file descriptor value.

int setSoTimeout (int)
 Defines the timeout before closing connection to the other end of communication.

const char * getClassName ()
 Returns the name of the current class.


Static Public Methods

int installedCPUs ()
 This will return how many CPUs are installed in the system.

double cpuSpeed ()
 This will return the CPU speed in megahertz.

int totalMemory ()
 Will return the total amount of system memory.

int freeMemory ()
 Will return the total amount of free system memory.

void usleep (Uint32 usec)
 Will freeze the software for usec microseconds.


Protected Methods

int CreateSocket (const char *thehost, int theport)
 This routine creates the socket by calling socket(2) and resolving the argument thehost to its IP representation in case the address is given as a name, this socket is connected to the port theport.

int setSockOption (int opname, void *optval, unsigned int siz)
 Is an interface to setsockopt.

void setClassName (const char *n)
 Call this method when you need to set the name of the class you're creating, typically in it's constructor, remember that you must set the classname for every class you create, that way you can have more information while debugging.


Protected Attributes

char * host
 Stores the hostname where the socket is going to be connected.

TCPsocket tcpsock
 This file descriptor represents the socket itself as returned by socket(2) and accept(2).

int port
 Defines the communications port used by the socket or the port which the socket server uses to listen requests.


Constructor & Destructor Documentation

clawsoft::Socket::Socket   [inline]
 

This is a default constructor that does nothing.

clawsoft::Socket::Socket const char *    thehost,
int    theport
 

This constructor tekas as an argument the host location as an IP number or as a name, also the port to connect to, take in count that in the very moment that this class is instantiated the socket would try to connect with thw remote host inmediately.

clawsoft::Socket::Socket TCPsocket    s,
int    pport
 

This constructor takes as an argument the file descriptor defined for an already opened socket, the main idea is that you can use it in a subclass so you can have the same functionality ypu do when you use the other constructors.

clawsoft::Socket::Socket const Socket &    s
 

This is a copy constructor.

clawsoft::Socket::~Socket   [inline]
 

This destructor does nothing.


Member Function Documentation

void clawsoft::Socket::close void   
 

Closes the communications channel with the remote host inmmediately.

double clawsoft::System::cpuSpeed   [static, inherited]
 

This will return the CPU speed in megahertz.

int clawsoft::Socket::CreateSocket const char *    thehost,
int    theport
[protected]
 

This routine creates the socket by calling socket(2) and resolving the argument thehost to its IP representation in case the address is given as a name, this socket is connected to the port theport.

int clawsoft::System::freeMemory   [static, inherited]
 

Will return the total amount of free system memory.

const char * clawsoft::Object::getClassName   [inherited]
 

Returns the name of the current class.

const int clawsoft::Socket::getPort   [inline]
 

Returns the port associated with this socket.

const TCPsocket clawsoft::SocketBase::getSocket   [inline, inherited]
 

Returns the socket's file descriptor value.

int clawsoft::System::installedCPUs   [static, inherited]
 

This will return how many CPUs are installed in the system.

Socket & clawsoft::Socket::operator<< const char *    str
 

Sends a string to the remote host.

Socket & clawsoft::Socket::operator<< String   str
 

Sends a string to the remote host THIS IS NOT A THREAD SAFE FUNCTION!!!!!

Socket & clawsoft::Socket::operator<< const Uint64    value
 

Sends a 64bit unsigned quantity to the remote host.

Socket & clawsoft::Socket::operator<< const unsigned long    value
 

Sends an unsigned long(32bit) quantity to the remote host.

Socket& clawsoft::Socket::operator<< const long    value
 

Sends a long(32bit) quantity to the remote host.

Socket & clawsoft::Socket::operator<< const long double    value
 

Sends a 96bit floating point value to the remote host.

Socket & clawsoft::Socket::operator<< const double    value
 

Sends a double presicion value to the remote host.

Socket & clawsoft::Socket::operator<< const float    value
 

Sends a floating point value to the remote host.

Socket & clawsoft::Socket::operator<< const unsigned int    value
 

Sends an unsigned integer quantity to the remote host.

Socket & clawsoft::Socket::operator<< const int    value
 

Sends an integer quantity to the remote host.

Socket & clawsoft::Socket::operator<< const char    chr
 

Sends a char to the other host.

Socket & clawsoft::Socket::operator>> String   str
 

Receives a string from the remote host.

Socket & clawsoft::Socket::operator>> Uint64 &    value
 

Receives a 64bit unsigned quantity from the remote host.

Socket & clawsoft::Socket::operator>> unsigned long &    value
 

Receives an unsigned long(32bit) quantity from the remote host.

Socket & clawsoft::Socket::operator>> long &    value
 

Receives a long(32bit) quantity from the remote host.

Socket & clawsoft::Socket::operator>> long double &    value
 

Receives a 96bit floating point value from the remote host.

Socket & clawsoft::Socket::operator>> double &    value
 

Receives a double presicion value from the remote host.

Socket & clawsoft::Socket::operator>> float &    value
 

Receives a floating point value from the remote host.

Socket & clawsoft::Socket::operator>> unsigned int &    value
 

Receives an unsigned integer quantity from the remote host.

Socket & clawsoft::Socket::operator>> int &    value
 

Receives an integer quantity from the remote host.

Socket & clawsoft::Socket::operator>> char &    chr
 

PLEASE RECONSIDER THE USE OF SDL_Net YOU SHOULD START USING ANOTHER OS INDEPENDENT NETWORK LIBRARY.

void clawsoft::Socket::read void *    buffer,
unsigned long    size
 

Use this method when you need to receive a fixed lenght buffer of bytes from the remote host, the routine will cut the buffer in chunks so the transfer can be safelly completed without out of memory error that might be caused if you attempt to receive a very big buffer of data.

void clawsoft::Object::setClassName const char *    n [protected, inherited]
 

Call this method when you need to set the name of the class you're creating, typically in it's constructor, remember that you must set the classname for every class you create, that way you can have more information while debugging.

int clawsoft::SocketBase::setSockOption int    opname,
void *    optval,
unsigned int    siz
[protected, inherited]
 

Is an interface to setsockopt.

int clawsoft::SocketBase::setSoTimeout int    [inherited]
 

Defines the timeout before closing connection to the other end of communication.

int clawsoft::System::totalMemory   [static, inherited]
 

Will return the total amount of system memory.

void clawsoft::System::usleep Uint32    usec [static, inherited]
 

Will freeze the software for usec microseconds.

void clawsoft::Socket::write const void *    buffer,
unsigned long    size
 

Use this method when you need to send a fixed lenght buffer of bytes to the remote host, the routine will cut the buffer in chunks so the transfer can be safelly completed without out of memory error that might be caused if you attempt to send a very big buffer of data.


Field Documentation

char* clawsoft::Socket::host [protected]
 

Stores the hostname where the socket is going to be connected.

int clawsoft::SocketBase::port [protected, inherited]
 

Defines the communications port used by the socket or the port which the socket server uses to listen requests.

TCPsocket clawsoft::SocketBase::tcpsock [protected, inherited]
 

This file descriptor represents the socket itself as returned by socket(2) and accept(2).


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

Authors:

Juan V. Guerrero
Jannette C. Mejia
Juan C. Guevara

Powered by:

SourceForgeLogo