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

netServerExample.cpp

00001 /*
00002 MobileRobots Advanced Robotics Interface for Applications (ARIA)
00003 Copyright (C) 2004, 2005 ActivMedia Robotics LLC
00004 Copyright (C) 2006, 2007 MobileRobots Inc.
00005 
00006      This program is free software; you can redistribute it and/or modify
00007      it under the terms of the GNU General Public License as published by
00008      the Free Software Foundation; either version 2 of the License, or
00009      (at your option) any later version.
00010 
00011      This program is distributed in the hope that it will be useful,
00012      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014      GNU General Public License for more details.
00015 
00016      You should have received a copy of the GNU General Public License
00017      along with this program; if not, write to the Free Software
00018      Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019 
00020 If you wish to redistribute ARIA under different terms, contact 
00021 MobileRobots for information about a commercial version of ARIA at 
00022 robots@mobilerobots.com or 
00023 MobileRobots Inc, 19 Columbia Drive, Amherst, NH 03031; 800-639-9481
00024 */
00025 
00026 #include "Aria.h"
00027 
00031 // to use the net server, start this program, then telnet to localhost
00032 // 7171, and type in 'password' and press enter, it should then be
00033 // self explanatory
00034 
00035 // this function just prints out what the client entered and then sends some 
00036 // data back
00037 void test(char **argv, int argc, ArSocket *socket)
00038 {
00039   int i;
00040   printf("Client said: ");
00041   for (i = 0; i < argc; ++i)
00042     printf("%s ", argv[i]);
00043   printf("\n");
00044   socket->writeString("Testing, 1, 2, 3");
00045 }
00046 
00047 
00048 int main(int argc, char **argv)
00049 {
00050   // Initialize Aria
00051   Aria::init();
00052   // we need a server
00053   ArNetServer server;
00054   // a callback for our test function
00055   ArGlobalFunctor3<char **, int, ArSocket *> testCB(&test);
00056 
00057   // start the server up without a robot on port 7171 with a password
00058   // of password and allow multiple clients
00059   if (!server.open(NULL, 7171, "password", true))
00060   {
00061     printf("Could not open server.\n");
00062     exit(1);
00063   }
00064   
00065   // add our test command
00066   server.addCommand("test", &testCB, "this simply prints out the command given on the server");
00067   server.addCommand("tesSst", &testCB, "this simply prints out the command given on the server");
00068   
00069   //server.setLoggingDataSent(true);
00070   //server.setLoggingDataReceived(true);
00071   // run while the server is running
00072   while (server.isOpen() && Aria::getRunning())
00073   {
00074     server.runOnce();
00075     ArUtil::sleep(1);
00076   }
00077   server.close();
00078   return 0;  
00079 }

Generated on Tue Feb 20 10:51:42 2007 for Aria by  doxygen 1.4.0