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

netServerExample.cpp

Shows how to use ArNetServer, a simple text command receiver

#include "Aria.h"

// to use the net server, start this program, then telnet to localhost
// 7171, and type in 'password' and press enter, it should then be
// self explanatory

// this function just prints out what the client entered and then sends some 
// data back. You could modify it to, for example, control the robot with
// different commands.
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");
  socket->writeString("Thank you, command received.");
}


int main(int argc, char **argv)
{
  // Initialize Aria
  Aria::init();
  // we need a server
  ArNetServer server;
  // a callback for our test function
  ArGlobalFunctor3<char **, int, ArSocket *> testCB(&test);

  // start the server up without a robot on port 7171 with a password
  // of password and allow multiple clients
  if (!server.open(NULL, 7171, "password", true))
  {
    printf("Could not open server.\n");
    exit(1);
  }
  
  // add our test command
  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");
  
  //server.setLoggingDataSent(true);
  //server.setLoggingDataReceived(true);
  // run while the server is running
  while (server.isOpen() && Aria::getRunning())
  {
    server.runOnce();
    ArUtil::sleep(1);
  }
  server.close();
  return 0;  
}

Generated on Thu Jan 7 10:34:38 2010 for Aria by  doxygen 1.4.2