netServerExample.cpp

Shows how to use ArNetServer, a simple text command receiver

00001 #include "Aria.h"
00002 
00007 // to use the net server, start this program, then telnet to localhost
00008 // 7171, and type in 'password' and press enter, it should then be
00009 // self explanatory
00010 
00011 // this function just prints out what the client entered and then sends some 
00012 // data back. You could modify it to, for example, control the robot with
00013 // different commands.
00014 void test(char **argv, int argc, ArSocket *socket)
00015 {
00016   int i;
00017   printf("Client said: ");
00018   for (i = 0; i < argc; ++i)
00019     printf("\t%s\n", argv[i]);
00020   printf("\n");
00021   socket->writeString("Thank you, command received.");
00022 }
00023 
00024 
00025 int main(int argc, char **argv)
00026 {
00027   // Initialize Aria
00028   Aria::init();
00029   // we need a server
00030   ArNetServer server;
00031   // a callback for our test function
00032   ArGlobalFunctor3<char **, int, ArSocket *> testCB(&test);
00033 
00034   // start the server up without a robot on port 7171 with a password
00035   // of password and allow multiple clients
00036   if (!server.open(NULL, 7171, "password", true))
00037   {
00038     printf("Could not open server.\n");
00039     exit(1);
00040   }
00041   
00042   // add our test command
00043   server.addCommand("test", &testCB, "this simply prints out the command given on the server");
00044   server.addCommand("test2", &testCB, "this simply prints out the command given on the server");
00045   
00046   //server.setLoggingDataSent(true);
00047   //server.setLoggingDataReceived(true);
00048   // run while the server is running
00049   while (server.isOpen() && Aria::getRunning())
00050   {
00051     server.runOnce();
00052     ArUtil::sleep(1);
00053   }
00054   server.close();
00055   return 0;  
00056 }

Generated on Fri Jul 31 12:36:37 2009 for Aria by  doxygen 1.4.7