NetPeerSocket Class Reference
[Networking]

A peer to peer network socket class, derived from NetStandardSocket. More...

#include <netpeersocket.h>

Inheritance diagram for NetPeerSocket:

Inheritance graph
[legend]
Collaboration diagram for NetPeerSocket:

Collaboration graph
[legend]
List of all members.

Public Member Functions

DECLSPEC NetPeerSocket (const char *name, NetPeerManager *parent, TCPsocket connection=NULL)
DECLSPEC NetPeerSocket (const char *name, NetPeerManager *parent, IPaddress ip)
DECLSPEC NetPeerSocket (TiXmlElement *el, NetPeerManager *parent)
virtual const char * getClassName ()
const char * getNetName ()
 
Returns:
the name of the machine in the network

DECLSPEC Uint32 fastPing ()
DECLSPEC void requestPing ()
Uint32 lastPing () const
int getListenPort ()
 
Returns:
the port on which this machine can be connected


Static Public Member Functions

static void newsocket (void *presult, BasicObject *o, void *xmldata)

Protected Member Functions

virtual DECLSPEC void handleData (NetBasicData *d)
virtual DECLSPEC bool onReceive ()
virtual DECLSPEC void onConnect ()
virtual DECLSPEC void onPing ()

Protected Attributes

char chName [PEER_MAX_NAME+1]
 the name of the host machine in the network
int nListenPort
 port on which one can connect to the socket's host

Detailed Description

A peer to peer network socket class, derived from NetStandardSocket.

Todo:
update onRecieve()!!!
This class implements socket functions for peer to peer communication. It works closely together with NetPeerManager.

See also:
NetPeerManager


Constructor & Destructor Documentation

NetPeerSocket::NetPeerSocket ( const char *  name,
NetPeerManager parent,
TCPsocket  connection = NULL 
)

Constructor. Usually the 3rd param is only used internally in the Netrinjo library.

Parameters:
connection the SDL TCPsocket to use, or NULL, if no connection is used.

NetPeerSocket::NetPeerSocket ( const char *  name,
NetPeerManager parent,
IPaddress  ip 
)

Constructor. Can be used to establish a connection to a host.

Parameters:
ip the host's IP address, that should be connected.
Warning:
this construction can take some time, if the host is not reachable immediatelly.

NetPeerSocket::NetPeerSocket ( TiXmlElement el,
NetPeerManager parent 
)

Constructor with XML-data.

Parameters:
el the XML-data,


Member Function Documentation

virtual const char* NetPeerSocket::getClassName (  )  [inline, virtual]

This function should be overriden in every sub-class of BasicObject!

Returns:
the name of the class.

Reimplemented from NetStandardSocket.

Uint32 NetPeerSocket::fastPing (  ) 

Todo:
use UDP! Gets the ping to the host immediatelly. This function waits until the host responded the ping request.
Returns:
the time in msecs, that went over until the response came.
Warning:
using this function while other network-exchange on the same port with the host will cause errors!
See also:
requestPing, lastPing

void NetPeerSocket::requestPing (  ) 

Requests a ping from the host and returns immediatelly. When the host responded, the duration of the ping can be asked with lastPing().
In comparison to fastPing() this function is safe, but usually returns a higher result.

Uint32 NetPeerSocket::lastPing (  )  const [inline]

Returns:
the duration of the last ping to the host
See also:
requestPing()

void NetPeerSocket::handleData ( NetBasicData d  )  [protected, virtual]

Handles incomming data. This needs not to be used by the app. It is used internally in the Netrinjo engine.

Parameters:
d the data, that arrived

bool NetPeerSocket::onReceive (  )  [protected, virtual]

Calls the callback function, as set by setReceiveCallback(). The 3rd param of the callback-function is used as a pointer to a boolean value. If this is set false, the socket will close.

Returns:
true by default, false if the value of the pointer in the 3rd param is set to false.

Reimplemented from NetStandardSocket.

void NetPeerSocket::onConnect (  )  [protected, virtual]

Called, after a connection has been established successfully. If you want to overwrite this method, do not forget to call the parent class's onConnect();

Reimplemented from NetStandardSocket.

virtual DECLSPEC void NetPeerSocket::onPing (  )  [inline, protected, virtual]

Called when a ping answer arrived, so tPing has just been refreshed.


The documentation for this class was generated from the following files:
Generated on Wed May 9 17:36:31 2007 for netrinjo by  doxygen 1.5.1