Planeshift
Public Member Functions | Protected Member Functions | Protected Attributes

psNetConnection Class Reference

Client-side UDP handler. More...

#include <connection.h>

List of all members.

Public Member Functions

virtual void Broadcast (MsgEntry *me, int scope, int guildID)
 Broadcasting makes no sense in a single connection class. Just wraps SendMessage.
bool Connect (const char *server, int port)
 Connects to the server and starts the thread to poll it.
virtual void DecRef ()
 Necessary CS definition and stub function.
void DisConnect ()
 Kills the thread and closes the socket.
virtual int GetRefCount ()
virtual void IncRef ()
 Necessary CS definition and stub function.
bool Initialize (iObjectRegistry *object_reg)
 Just some basic initialization for the class.
virtual void Multicast (MsgEntry *me, const csArray< PublishDestination > &multi, uint32_t except, float range)
 Multicasting makes no sense in a single connection class. Just wraps SendMessage.
 psNetConnection (int queueLength=100)
 Creates a queue of messages queueLength wide.
virtual ~psNetConnection ()
 Disconnects and terminates the thread.

Protected Member Functions

void CheckLinkDead (csTicks time)
 This checks the time since the last packet received from the server.
virtual ConnectionGetConnByIP (LPSOCKADDR_IN addr)
 Returns the same address back if the address is correct. NULL if not.
virtual ConnectionGetConnByNum (uint32_t clientnum)
 Returns the server connection if the clientnum is 0.
virtual bool HandleUnknownClient (LPSOCKADDR_IN addr, MsgEntry *data)
 Another overridden function only used by multi-connection class NetManager.
void Run ()
 this is the main thread function...

Protected Attributes

MsgQueueinQueue
 This is the inbound queue to the client.
iObjectRegistry * object_reg
Connectionserver
 Connection class holds the IP address and port we are using here.
bool shouldRun
 When this is false, thread will finish it's last loop and exit.

Detailed Description

Client-side UDP handler.

Implementation of client side network connection on top of the common network code in psnet. For details about the functions look at connection.h and netbase.h. This class differs from NetManager in that it only has a single connection (to the server) as opposed to NetManager which is managing many client connections at once. This means several functions are overridden as empty functions because they aren't relevant with a single connection.

Definition at line 42 of file connection.h.


Constructor & Destructor Documentation

psNetConnection::psNetConnection ( int  queueLength = 100)

Creates a queue of messages queueLength wide.

virtual psNetConnection::~psNetConnection ( ) [virtual]

Disconnects and terminates the thread.


Member Function Documentation

virtual void psNetConnection::Broadcast ( MsgEntry me,
int  scope,
int  guildID 
) [virtual]

Broadcasting makes no sense in a single connection class. Just wraps SendMessage.

Implements NetBase.

void psNetConnection::CheckLinkDead ( csTicks  time) [protected]

This checks the time since the last packet received from the server.

This function tracks how long it has been since the last packet was received from the server. If it has been longer than LINKDEAD_TIMEOUT msec, then it attempts to send a packet to the server just to get a response. If this goes longer than 5 retries, it kills the client.

bool psNetConnection::Connect ( const char *  server,
int  port 
)

Connects to the server and starts the thread to poll it.

Opens a non-blocking UDP socket to the specified server on the specified port, and kicks off the thread which will handle sending and receiving on this socket.

Parameters:
server,:The text hostname or IP address of the destination
port,:The port number to try on the server.
Returns:
True if successful connection is made, false if error.
virtual void psNetConnection::DecRef ( ) [inline, virtual]

Necessary CS definition and stub function.

Definition at line 79 of file connection.h.

void psNetConnection::DisConnect ( )

Kills the thread and closes the socket.

virtual Connection* psNetConnection::GetConnByIP ( LPSOCKADDR_IN  addr) [protected, virtual]

Returns the same address back if the address is correct. NULL if not.

Implements NetBase.

virtual Connection* psNetConnection::GetConnByNum ( uint32_t  clientnum) [protected, virtual]

Returns the server connection if the clientnum is 0.

Implements NetBase.

virtual int psNetConnection::GetRefCount ( ) [inline, virtual]

Definition at line 82 of file connection.h.

virtual bool psNetConnection::HandleUnknownClient ( LPSOCKADDR_IN  addr,
MsgEntry data 
) [protected, virtual]

Another overridden function only used by multi-connection class NetManager.

Implements NetBase.

virtual void psNetConnection::IncRef ( ) [inline, virtual]

Necessary CS definition and stub function.

Definition at line 76 of file connection.h.

bool psNetConnection::Initialize ( iObjectRegistry *  object_reg)

Just some basic initialization for the class.

virtual void psNetConnection::Multicast ( MsgEntry me,
const csArray< PublishDestination > &  multi,
uint32_t  except,
float  range 
) [virtual]

Multicasting makes no sense in a single connection class. Just wraps SendMessage.

Implements NetBase.

void psNetConnection::Run ( ) [protected]

this is the main thread function...


Member Data Documentation

This is the inbound queue to the client.

This class adds messages to this queue, and ClientMsgHandler pulls them out of this queue.

See also:
ClientMsgHandler.

Definition at line 106 of file connection.h.

iObjectRegistry* psNetConnection::object_reg [protected]

Definition at line 110 of file connection.h.

Connection class holds the IP address and port we are using here.

Definition at line 109 of file connection.h.

bool psNetConnection::shouldRun [protected]

When this is false, thread will finish it's last loop and exit.

Definition at line 113 of file connection.h.


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