Shows how to use ArNetServer, a simple text command receiver
#include "Aria.h"
void test(
char **argv,
int argc,
ArSocket *socket)
{
int i;
printf("Client said: ");
for (i = 0; i < argc; ++i)
printf("\t%s\n", argv[i]);
printf("\n");
}
int main(int argc, char **argv)
{
if (!server.
open(NULL, 7171,
"password",
true))
{
printf("Could not open server.\n");
return 1;
}
server.
addCommand(
"test", &testCB,
"this simply prints out the command given on the server");
server.
addCommand(
"test2", &testCB,
"this simply prints out the command given on the server");
{
}
return 0;
}
void close(void)
Closes the server.
Definition: ArNetServer.cpp:522
Functor for a global function with 3 parameters.
Definition: ArFunctor.h:813
bool addCommand(const char *command, ArFunctor3< char **, int, ArSocket * > *functor, const char *help)
Adds a new command.
Definition: ArNetServer.cpp:164
int writeString(const char *str,...)
Writes a string to the socket (adding end of line characters)
Definition: ArSocket.cpp:244
static void exit(int exitCode=0)
Shutdown all Aria processes/threads, call exit callbacks, and exit the program.
Definition: Aria.cpp:367
bool isOpen(void)
Sees if the server is running and open.
Definition: ArNetServer.cpp:261
bool open(ArRobot *robot, unsigned int port, const char *password, bool multipleClients=true, const char *openOnIP=NULL)
Initializes the server.
Definition: ArNetServer.cpp:105
void runOnce(void)
the internal sync task we use for our loop
Definition: ArNetServer.cpp:335
static void init(SigHandleMethod method=SIGHANDLE_THREAD, bool initSockets=true, bool sigHandleExitNotShutdown=true)
Initialize Aria global data struture and perform OS-specific initialization, including adding OS sign...
Definition: Aria.cpp:128
static void sleep(unsigned int ms)
Sleep for the given number of milliseconds.
Definition: ariaUtil.cpp:151
socket communication wrapper
Definition: ArSocket.h:76
Class for running a simple net server to send/recv commands via text.
Definition: ArNetServer.h:72
static bool getRunning(void)
Sees if Aria is still running (mostly for the thread in main)
Definition: Aria.cpp:753