PixelLightAPI  .
Public Member Functions | Protected Member Functions
PLCore::Host Class Reference

Network host base class. More...

#include <Host.h>

Inheritance diagram for PLCore::Host:
Inheritance graph
[legend]

List of all members.

Public Member Functions

PLCORE_API Host ()
 Constructor.
virtual PLCORE_API ~Host ()
 Destructor.
PLCORE_API ConnectionConnect (const String &sServerName, uint32 nPort)
 Connect to a server.
bool IsListening () const
 Check if the host is currently listening for new connections.
PLCORE_API void Listen (uint32 nPort)
 Start listening for new connections.
PLCORE_API void ClosePort ()
 Stop listening for new connections.
PLCORE_API void CloseConnections ()
 Close all connections.
void Close ()
 Close host (close all connections and stop listening for new connections)
uint32 GetPort () const
 Returns the currently used port number.
uint32 GetMaxConnections () const
 Returns the maximum number of allowed connections.
void SetMaxConnections (uint32 nMaxConnections)
 Sets the maximum number of allowed connections.
const Container< Connection * > & GetConnections () const
 Get list of active connection.
PLCORE_API void RemoveInactiveConnections ()
 Remove inactive connections.

Protected Member Functions

virtual PLCORE_API ConnectionCreateIncomingConnection ()
 Create a new incoming connection.
virtual PLCORE_API ConnectionCreateOutgoingConnection ()
 Create a new outgoing connection.
virtual PLCORE_API void OnConnect (Connection &cConnection)
 Called when a connection is established.
virtual PLCORE_API void OnDisconnect (Connection &cConnection)
 Called when a connection is closed.

Detailed Description

Network host base class.

Remarks:
Base class for a 'network partner'. That is any node in a network, which can open or accept connection to one or more other nodes. In a classic client/server architecture, one host is the client and another is the server to which all clients connect. In other network architectures, such as peer-to-peer, the network consists of several nodes of the same type, that connect to one another.

Constructor & Destructor Documentation

PLCORE_API PLCore::Host::Host ( )
virtual PLCORE_API PLCore::Host::~Host ( ) [virtual]

Destructor.


Member Function Documentation

PLCORE_API Connection* PLCore::Host::Connect ( const String sServerName,
uint32  nPort 
)

Connect to a server.

Parameters:
[in]sServerNameServer name
[in]nPortPort number
Returns:
Connection, a null pointer on error
bool PLCore::Host::IsListening ( ) const [inline]

Check if the host is currently listening for new connections.

Returns:
'true' if host is listening for new connections, else 'false'
PLCORE_API void PLCore::Host::Listen ( uint32  nPort)

Start listening for new connections.

Parameters:
[in]nPortPort at which the host is listening
Remarks:
This function will start a listener thread and then return, so this function does not block the caller thread. When a connection is opened, it will call the virtual function CreateConnection() and then OnConnection() upon a successful connect. You can use SetMaxConnection() to set the maximum number of connections.
PLCORE_API void PLCore::Host::ClosePort ( )

Stop listening for new connections.

Remarks:
This function will stop the host listening for new connection, but all current connections will still remain open. See CloseConnection() and Close() for closing the host completely.
PLCORE_API void PLCore::Host::CloseConnections ( )

Close all connections.

Remarks:
This function closes all active connections, but does not stop listening for new connections. See StopListen() and Close() for closing the host completely.
void PLCore::Host::Close ( ) [inline]

Close host (close all connections and stop listening for new connections)

uint32 PLCore::Host::GetPort ( ) const [inline]

Returns the currently used port number.

Returns:
Number of the currently used port
uint32 PLCore::Host::GetMaxConnections ( ) const [inline]

Returns the maximum number of allowed connections.

Returns:
Maximum number of allowed connections
void PLCore::Host::SetMaxConnections ( uint32  nMaxConnections) [inline]

Sets the maximum number of allowed connections.

Parameters:
[in]nMaxConnectionsMaximum number of allowed connections
const Container< Connection * > & PLCore::Host::GetConnections ( ) const [inline]

Get list of active connection.

Returns:
List of connections

Remove inactive connections.

virtual PLCORE_API Connection* PLCore::Host::CreateIncomingConnection ( ) [protected, virtual]

Create a new incoming connection.

Returns:
Connection

Reimplemented in PLCore::HttpServer, PLCore::Client, and PLCore::Server.

virtual PLCORE_API Connection* PLCore::Host::CreateOutgoingConnection ( ) [protected, virtual]

Create a new outgoing connection.

Returns:
Connection

Reimplemented in PLCore::HttpClient, PLCore::Client, and PLCore::Server.

virtual PLCORE_API void PLCore::Host::OnConnect ( Connection cConnection) [protected, virtual]

Called when a connection is established.

Parameters:
[in]cConnectionThe new connection

Reimplemented in PLCore::HttpServer.

virtual PLCORE_API void PLCore::Host::OnDisconnect ( Connection cConnection) [protected, virtual]

Called when a connection is closed.

Parameters:
[in]cConnectionThe closed connection

Reimplemented in PLCore::HttpClient, and PLCore::HttpServer.


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


PixelLight PixelLight 0.9.10-R1
Copyright (C) 2002-2011 by The PixelLight Team
Last modified Fri Dec 23 2011 15:51:15
The content of this PixelLight document is published under the
Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported