Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages | Examples

ArNetServer Class Reference

#include <ArNetServer.h>

List of all members.


Detailed Description

Class for running a simple net server to send/recv commands via text.

This class is for running a simple server which will have a list of commands to use and a fairly simple set of interactions... Start the server with the open function, add commands with the addCommand function and remove commands with remCommand, and close the server with the close function.

It has a built in mutex, if you only use sendToAllClients through the normal commands or during the robot loop you don't need to worry about locking anything and the server is locked before any of the callbacks for the commands are called so you really only need to lock the server if you're dealing with it from outside the way.

Examples:

netServerExample.cpp.


Public Member Functions

bool addCommand (const char *command, ArFunctor3< char **, int, ArSocket * > *functor, const char *help)
 Adds a new command.
 ArNetServer (bool addAriaExitCB=true)
 Constructor.
void close (void)
 Closes the server.
const char * getExtraString (void)
 Gets an extra string that the server holds for passing around.
bool getLoggingDataReceived (void)
 Gets whether we are logging all data received or not.
bool getLoggingDataSent (void)
 Gets whether we are logging all data sent or not.
bool getUseWrongEndChars (void)
 Gets whether we're using the wrong (legacy) end chars or not.
void internalAddSocketToDeleteList (ArSocket *socket)
 The internal function that adds a client to our delete list.
void internalAddSocketToList (ArSocket *socket)
 The internal function that adds a client to our list.
void internalEcho (char **argv, int argc, ArSocket *socket)
 The internal function for echo.
void internalGreeting (ArSocket *socket)
 the internal function that gives the greeting message
void internalHelp (char **argv, int argc, ArSocket *socket)
 The internal function for the help cb.
void internalHelp (ArSocket *socket)
 The internal function that does the help.
void internalQuit (char **argv, int argc, ArSocket *socket)
 The internal function for closing this connection.
void internalShutdownServer (char **argv, int argc, ArSocket *socket)
 The internal function for shutting down.
bool isOpen (void)
 Sees if the server is running and open.
int lock ()
 Lock the server.
bool open (ArRobot *robot, unsigned int port, const char *password, bool multipleClients=true, const char *openOnIP=NULL)
 Initializes the server.
void parseCommandOnSocket (ArArgumentBuilder *args, ArSocket *socket, bool allowLog=true)
 The internal function for parsing a command on a socket.
bool remCommand (const char *command)
 Removes a command.
void runOnce (void)
 the internal sync task we use for our loop
void sendToAllClients (const char *str,...)
 Sends the given string to all the clients.
void sendToAllClientsPlain (const char *str)
 Sends the given string to all the clients, no varargs, wrapper for java.
void sendToClient (ArSocket *socket, const char *ipString, const char *str,...)
 Sends the given string to the (hopefully) the client given (this method may go away).
void sendToClientPlain (ArSocket *socket, const char *ipString, const char *str)
 Sends the given plain string to the (hopefully) the client given (this method may go away).
void setExtraString (const char *str)
 Sets an extra string that the server holds for passing around.
void setLoggingDataReceived (bool loggingData)
 Sets whether we are logging all data received or not.
void setLoggingDataSent (bool loggingData)
 Sets whether we are logging all data sent or not.
void setUseWrongEndChars (bool useWrongEndChars)
 Sets whether we're using the wrong (legacy) end chars or not.
void squelchNormal (void)
 This squelchs all the normal commands and help.
int tryLock ()
 Try to lock the server without blocking.
int unlock ()
 Unlock the server.
 ~ArNetServer ()
 Destructor.

Protected Attributes

ArSocket myAcceptingSocket
ArFunctorC< ArNetServermyAriaExitCB
std::list< ArSocket * > myConnectingConns
std::list< ArSocket * > myConns
std::list< ArSocket * > myDeleteList
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myEchoCB
std::string myExtraString
std::map< std::string, ArFunctor3<
char **, int, ArSocket * > *,
ArStrCaseCmpOp
myFunctorMap
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myHelpCB
std::map< std::string, std::string,
ArStrCaseCmpOp
myHelpMap
bool myLoggingDataReceived
bool myLoggingDataSent
bool myMultipleClients
ArMutex myMutex
bool myOpened
std::string myPassword
unsigned int myPort
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myQuitCB
ArRobotmyRobot
ArSocket myServerSocket
ArFunctor3C< ArNetServer,
char **, int, ArSocket * > 
myShutdownServerCB
bool mySquelchNormal
ArFunctorC< ArNetServermyTaskCB
bool myUseWrongEndChars
bool myWantToClose


Member Function Documentation

bool ArNetServer::addCommand const char *  command,
ArFunctor3< char **, int, ArSocket * > *  functor,
const char *  help
 

Adds a new command.

This adds a command to the list, when the command is given the broken up argv and argc are given along with the socket it came from (so that acks can occur)

Examples:
netServerExample.cpp.

bool ArNetServer::getLoggingDataReceived void   ) 
 

Gets whether we are logging all data received or not.

Returns:
if true data will be logged which means that all commands received from clients are logged

bool ArNetServer::getLoggingDataSent void   ) 
 

Gets whether we are logging all data sent or not.

Returns:
if true data will be logged which means that all data sent out to the all the clients will be logged

bool ArNetServer::getUseWrongEndChars void   ) 
 

Gets whether we're using the wrong (legacy) end chars or not.

Returns:
if true data will be logged which means that all data sent out to the all the clients will be logged

bool ArNetServer::open ArRobot robot,
unsigned int  port,
const char *  password,
bool  multipleClients = true,
const char *  openOnIP = NULL
 

Initializes the server.

Open the server, if you supply a robot this will run in the robots attached, if you do not supply a robot then it will be open and you'll have to call runOnce yourself (this is only recommended for advanced users)

Parameters:
robot the robot that this should be attached to and run in the sync task of or NULL not to run in any robot's task
port the port to start up the service on
password the password needed to use the service
multipleClients if false only one client is allowed to connect, if false multiple clients are allowed to connect or just one
openOnIP If not NULL, restrict server port to the network interface with this IP address. If NULL, accept connections from any network interface.
Returns:
true if the server could be started, false otherwise
Examples:
netServerExample.cpp.

bool ArNetServer::remCommand const char *  command  ) 
 

Removes a command.

Parameters:
command the command to remove
Returns:
true if the command was there to remove, false otherwise

void ArNetServer::sendToAllClients const char *  str,
  ...
 

Sends the given string to all the clients.

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

See also:
sendToAllClientsPlain()

void ArNetServer::sendToClient ArSocket socket,
const char *  ipString,
const char *  str,
  ...
 

Sends the given string to the (hopefully) the client given (this method may go away).

Java and Python Wrappers: Not available in Java or Python wrapper libraries.

See also:
sendToClientPlain()

void ArNetServer::setLoggingDataReceived bool  loggingData  ) 
 

Sets whether we are logging all data received or not.

Parameters:
loggingData if true data will be logged which means that all commands received from clients are logged

void ArNetServer::setLoggingDataSent bool  loggingData  ) 
 

Sets whether we are logging all data sent or not.

Parameters:
loggingData if true data will be logged which means that all data sent out to the all the clients will be logged

void ArNetServer::setUseWrongEndChars bool  useWrongEndChars  ) 
 

Sets whether we're using the wrong (legacy) end chars or not.

Set reverse line ending characters for compatibility with certain old clients.

Parameters:
useWrongEndChars if true the wrong end chars will be sent ('\n\r' instead of '\r\n'); a nonstandard, deprecated line ending, but may be required for certain old clients.


The documentation for this class was generated from the following files:
Generated on Thu Jan 7 10:34:42 2010 for Aria by  doxygen 1.4.2