/************************************************************* * Name: commsExample.cc * Description: Illustrates how to use communicate.h for * communicating between robot processes. * * REFER TO FUNCTION HEADER COMMENTS FOR INTERPRETATION * * To run this code in 2 processes, give the following commands * in 2 separate windows: * * In window #1: * linux>./commsExample 1 6000 2 6001 * * In window #2: * linux>./commsExample 2 6001 1 6001 * * The first command runs this program (commsExample), setting * the current robot's ID to 1, using port 6000, and setting the * robot friend's ID to 2, using port 6001. The second command * does the opposite: it sets the current robot's ID to 2, using * port 6001, and it sets the robot friend's ID to 1, using port * 6000. **************************************************************/ #include #include #include #include #include #include #include #include #include "communicate.h" using namespace std; /********************************************************************** * Utility to convert an integer base 10 to ascii (string) *********************************************************************/ void itoa(int n, char s[]) { short i, j, k; int c, sign; if((sign = n) < 0) n = -n; i = 0; do { s[i++] = n % 10 + '0'; } while((n/=10) > 0); if(sign < 0) s[i++] = '-'; s[i] = '\0'; k = i-1; for(j=0; j