Beaming Scene Service  2.0
RakNet wrapper for managing data communications between multiple Beaming clients
netClient/sampleClient.cpp
Go to the documentation of this file.
00001 
00011 #include <iostream>
00012 #include <stdio.h>
00013 #include "Kbhit.h"
00014 #include "Getche.h"
00015 #include "client.h"
00016 #include <stdlib.h>
00017 #include <time.h>
00018 #if defined(_WIN32)
00019 #include <windows.h>
00020 #else
00021 #include<unistd.h>
00022 #include<cstdlib>
00023 #endif
00024 
00025 
00026 int main(int argc, char**argv)
00027 {
00028         srand((unsigned)time(0));
00029         float px,py,pz,eh,ep,er,hh,hp,hr;
00032         int connected = startclient(/*"128.16.7.66"*/"127.0.0.1", 12050,"UCL","VISITOR","m016.cfg",false);
00033 #if defined(_WIN32)
00034         Sleep(100);
00035 #else
00036         sleep(2);
00037 #endif
00038 
00039         printf("Commands:\n(Q)uit\n'C'reate objects\n'M'ove objects\n'R'otate objects\n'F'etch remote objects\n'D'estroy all objects\n");
00040         //printf("connected = %i\n", connected);
00041         char m_id[32];
00042         getMyGUID(m_id);
00043         printf("My GUID is %s\n",m_id);
00044 
00045         bool quit = false;
00046         char ch;
00047         char buf[32];
00048         float j=0.f;
00049         char iddata[128];
00050         char type[128];
00051         char name[128];
00052         char my_config[128];
00053         char fname[128], lname[128];
00054         strcpy(name,"");
00055         strcpy(type,"");
00056         strcpy(iddata,"");
00057         struct mystruct{
00058                 int x;
00059                 char name[28];
00060                 float myfloat;
00061         } st;                           
00062 
00063         strcpy(buf,"");
00064         float tx,ty,tz,ax,ay,az,aw = 0.f;
00067         addRocketBoxAvatar("avatar","m016.cfg");
00068         setAvatarName("avatar","John","Doe");
00071         addNode("Head","FACIAL");
00072         updateFacialNodes("Head",false,0.5f,0.2f,0.f,0.f,0.f);
00075         addNode("Audio1","AUDIO");
00076         updateAudioNodes("Audio1","127.0.0.1",0,"http://localhost","config file");
00077 
00078         while (!quit)
00079         {
00082                 check();
00083                 j = j + 0.001f;
00084                 if (j>2.f) 
00085                         j=-2.f;
00088                 updateRocketBoxAvatar("avatar","0",j,-1.18448e-015,-2.70976e-008,0,0.707106,-3.09086e-008,0.707107);
00089                 if (kbhit())
00090                 {
00091                         ch=getch();
00092                         if (ch=='q' || ch=='Q')
00093                         {
00094                                 printf("Quitting.\n");
00095                                 quit=true;
00096                         }
00097                         if (ch=='g' || ch=='G')
00098                         {
00099                                 static int i = 0;
00100                                 char genericnode[128];
00101                                 sprintf(genericnode,"mystruct%i",i++);
00102                                 addNode(genericnode,"GENERIC");
00103                                 void *somedata;
00104                                 if(!(somedata = malloc(1024))) {
00105                                         perror("failed to allocate buffer");
00106                                         return 0;
00107                                 }
00108                                 mystruct *s;
00109                                 s = &st;
00110                                 s->x = rand() % 11;
00111                                 strcpy(s->name,"wole");
00112                                 s->myfloat = 100.f * s->x;
00113                                 memcpy(somedata,s,1024);
00114                                 updateGenericNodes(genericnode,somedata,1024);
00115                                 printf("sending %s, %d, %.3f ...\n",((mystruct *)somedata)->name,((mystruct *)somedata)->x,((mystruct *)somedata)->myfloat);
00116                         }
00117                         if (ch=='c' || ch=='C')
00118                         {
00119                                 float m1[9] = {0.f};
00120                                 float m2[16] = {0.f};
00121                                 int datatype = rand() % 9;
00122                                 static int i = 0;
00123                                 sprintf(buf,"node%i",i++);
00124                                 //add node
00125                                 switch (datatype)
00126                                 {
00127                                 case 0:
00128                                         char avname[32];
00129                                         sprintf(avname,"avatar%i_",i++);
00130                                         addRocketBoxAvatar(avname,"m016.cfg");
00131                                         setAvatarName(avname,"Another",buf);
00132                                         updateRocketBoxAvatar(avname,"0",0,-1.18448e-015,-2.70976e-008,0,0.707106,-3.09086e-008,0.707107);
00133                                         break;
00134                                 case 1:
00135                                         addNode(buf,"FACIAL");
00136                                         updateFacialNodes(buf,false,0.f,0.f,0.f,0.f,0.f);
00137                                         break;
00138                                 case 2:
00139                                         addNode(buf,"EMOTION");
00140                                         updateEmotionNodes(buf,0,0,0);
00141                                         break;
00142                                 case 3:
00143                                         addNode(buf,"VIDEO");
00144                                         updateVideoNodes(buf,"127.0.0.1",0,"http://localhost",1,1,1,m1,m2);
00145                                         break;
00146                                 case 4:
00147                                         addNode(buf,"TACTILE");
00148                                         updateTactileNodes(buf,0,0,0);
00149                                         break;
00150                                 case 5:
00151                                         addNode(buf,"ROBOT");
00152                                         updateRobotNodes(buf,0,0,0,0,0,0,0,1,0,0,0,0);
00153                                         break;
00154                                 case 6:
00155                                         addNode(buf,"OBJECT");
00156                                         updateObjectNodes(buf,"127.0.0.1",0,"http://localhost",0,0,0,0,1,0,0);
00157                                         break;
00158                                 case 7:
00159                                         addNode(buf,"AUDIO");
00160                                         updateAudioNodes(buf,"127.0.0.1",0,"http://localhost","config file");
00161                                         break;
00162                                 case 8:
00163                                         addNode(buf,"POINTCLOUD");
00164                                         updatePointCloudNodes(buf,"127.0.0.1",0,"http://localhost",0,0,0,0);
00165                                         break;
00166                                 }
00167                         }
00168                         if (ch=='v' || ch=='V')
00169                         {
00170                                 static int v = 0;
00171                                 sprintf(buf,"node%i",v++);
00172                                 float m1[9] = {1.999f};
00173                                 float m2[16] = {3.123f};
00174                                 addNode(buf,"VIDEO");
00175                                 printf("%.3f\n",m1[0]);
00176                                 updateVideoNodes(buf,"127.0.0.1",0,"http://localhost",1,1,128,m1,m2);
00177                                 addNode(buf,"POINTCLOUD");
00178                                 updatePointCloudNodes(buf,"127.0.0.1",0,"http://localhost",0,0,0,0);
00179                         }
00180                         if (ch=='d' || ch=='D')
00181                         {
00182                                 deleteRocketBoxAvatar("avatar");
00183                         }
00184                         if (ch=='r' || ch=='R')
00185                         {
00186                                 static int k = 0.f;
00187                                 k = k + 0.01f;
00188                                 //updateRocketBoxAvatar("avatar","0",j,-1.18448e-015,-2.70976e-008,0,0.707106,-3.09086e-008,k);
00189                                 updateRocketBoxAvatar("avatar","0",j,-1.18448e-015,-2.70976e-008,0,0.707106,-3.09086e-008,k);
00190                         }
00191                         if (ch=='a' || ch=='A')
00192                         {
00193                                 char connectedclients[1024];
00194                                 char *guid, *node, *tmpid, *nodeid;
00195                                 char allnodes[2048], node_info[256];
00196                                 int loop = 0;
00197                                 float avdata[1024];
00198                                 char nodes[512];
00199                                 float data[7] = {0.f};
00205                                 printf("number of connected clients %i\n",getPeersID(connectedclients));
00206                                 //printf("connected clients (getPeersID): %s\n",connectedclients);
00207                                 for (guid = strtok (connectedclients, ";"); guid != NULL;
00208                                    guid = strtok (guid + strlen (guid) + 1, ";"))
00209                                 {
00210                                         strncpy (iddata, guid, sizeof (iddata));
00211                                         printf ("GUID: %s\n", iddata);
00215                                         printf("Number of nodes %i\n",getNodesInfo(iddata,allnodes));
00216                                         for (node = strtok (allnodes, ";"); node != NULL;
00217                                            node = strtok (node + strlen (node) + 1, ";"))
00218                                         {
00219                                                 strncpy (node_info, node, sizeof (node_info));
00220                                                 printf (" Node: %s\n", node_info);
00221                                                 for (tmpid = strtok (node_info, ","); tmpid != NULL;
00222                                                    tmpid = strtok (tmpid + strlen (tmpid) + 1, ","))
00223                                                 {
00224                                                         static char avid[256];
00225                                                         switch (loop) 
00226                                                         {
00227                                                         case 0:// first token is the avatar id
00228                                                                 printf ("  Avatar id: %s\n", tmpid);
00229                                                                 strncpy(avid,tmpid,sizeof(avid));
00230                                                                 break;
00231                                                         case 2: //third token is the TYPE
00232                                                                 if (!strcmp(tmpid,"AVATAR")) //only process if type is AVATAR
00233                                                                 {
00234                                                                         int c = 0;
00237                                                                         int count = getAvatarData(iddata,avid,nodes,avdata);
00238                                                                         for (nodeid = strtok (nodes, ","); nodeid != NULL;
00239                                                                            nodeid = strtok (nodeid + strlen (nodeid) + 1, ","))
00240                                                                         {
00241                                                                                 printf("   %s - %.3f %.3f %.3f %.3f %.3f %.3f %.3f\n",nodeid,
00242                                                                                         avdata[0+(c*7)],avdata[1+(c*7)],avdata[2+(c*7)],avdata[3+(c*7)],
00243                                                                                         avdata[4+(c*7)],avdata[5+(c*7)],avdata[6+(c*7)]);
00244                                                                                 c++;
00245                                                                         }
00249                                                                         if (getAvatarSpecificData(iddata,avid,"0",data))
00250                                                                                 printf("   Local-coord data for 0: %.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n",data[0],data[1],data[2],data[3],data[4],data[5],data[6]);
00254                                                                         if (getAvatarSpecificGlobalData(iddata,avid,"85",data))
00255                                                                                 printf("   World-coord data for 85: %.3f,%.3f,%.3f,%.3f,%.3f,%.3f,%.3f\n",data[0],data[1],data[2],data[3],data[4],data[5],data[6]);
00258                                                                         getAvatarName(iddata,avid,fname,lname);
00259                                                                         printf("   Avatar Name: %s %s\n",fname,lname);
00260                                                                 } else 
00261                                                                         printf("   Not AVATAR\n");
00262                                                                 break;
00263                                                         }
00264                                                         loop++;
00265                                                 }
00266                                                 loop=0;
00267                                         }
00268                                 }
00269                         }
00270                         if (ch=='h' || ch=='H')
00271                         {
00277                                 char connectedclients[1024];
00278                                 char *guid, *node, *tmpid, *nodeid;
00279                                 char allnodes[2048], node_info[256];
00280                                 int loop = 0;
00281                                 char nodes[512];
00282                                 float data[7] = {0.f};
00283                                 printf("number of connected clients %i\n",getPeersID(connectedclients));
00284                                 //printf("connected clients (getPeersID): %s\n",connectedclients);
00285                                 for (guid = strtok (connectedclients, ";"); guid != NULL;
00286                                    guid = strtok (guid + strlen (guid) + 1, ";"))
00287                                 {
00288                                         strncpy (iddata, guid, sizeof (iddata));
00289                                         printf ("GUID: %s\n", iddata);
00293                                         printf("Number of nodes %i\n",getNodesInfo(iddata,allnodes));
00294                                         for (node = strtok (allnodes, ";"); node != NULL;
00295                                            node = strtok (node + strlen (node) + 1, ";"))
00296                                         {
00297                                                 strncpy (node_info, node, sizeof (node_info));
00298                                                 printf (" Node: %s\n", node_info);
00299                                                 for (tmpid = strtok (node_info, ","); tmpid != NULL;
00300                                                    tmpid = strtok (tmpid + strlen (tmpid) + 1, ","))
00301                                                 {
00302                                                         static char genericid[256];
00303                                                         switch (loop) 
00304                                                         {
00305                                                         case 1:// second token is the node_id 
00306                                                                 printf ("  Generic id: %s\n", tmpid);
00307                                                                 strncpy(genericid,tmpid,sizeof(genericid));
00308                                                                 break;
00309                                                         case 2: //third token is the TYPE
00310                                                                 if (!strcmp(tmpid,"GENERIC")) //only process if type is GENERIC
00311                                                                 {
00314                                                                         int datasize; 
00315                                                                         void *receiveddata;
00316                                                                         if(!(receiveddata = malloc(1024))) {
00317                                                                                 perror("failed to allocate buffer");
00318                                                                                 return 0;
00319                                                                         }
00320                                                                         if (getGenericData(iddata,genericid,receiveddata,&datasize))
00321                                                                                 printf("   generic %s - %s,%d,%.3f\n",genericid,((mystruct *)receiveddata)->name,((mystruct *)receiveddata)->x,((mystruct *)receiveddata)->myfloat);
00322                                                                 } else 
00323                                                                         printf("   Not GENERIC\n");
00324                                                                 break;
00325                                                         }
00326                                                         loop++;
00327                                                 }
00328                                                 loop=0;
00329                                         }
00330                                 }
00331                         }
00332                         if (ch=='f' || ch=='F')
00333                         {
00339                                 char connectedclients[1024];
00340                                 char *guid, *node, *tmpid, *nodeid;
00341                                 char allnodes[2048], node_info[256];
00342                                 int loop = 0;
00343                                 char nodes[512];
00344                                 float data[7] = {0.f};
00345                                 printf("number of connected clients %i\n",getPeersID(connectedclients));
00346                                 //printf("connected clients (getPeersID): %s\n",connectedclients);
00347                                 for (guid = strtok (connectedclients, ";"); guid != NULL;
00348                                    guid = strtok (guid + strlen (guid) + 1, ";"))
00349                                 {
00350                                         strncpy (iddata, guid, sizeof (iddata));
00351                                         printf ("GUID: %s\n", iddata);
00355                                         printf("Number of nodes %i\n",getNodesInfo(iddata,allnodes));
00356                                         for (node = strtok (allnodes, ";"); node != NULL;
00357                                            node = strtok (node + strlen (node) + 1, ";"))
00358                                         {
00359                                                 strncpy (node_info, node, sizeof (node_info));
00360                                                 printf (" Node: %s\n", node_info);
00361                                                 for (tmpid = strtok (node_info, ","); tmpid != NULL;
00362                                                    tmpid = strtok (tmpid + strlen (tmpid) + 1, ","))
00363                                                 {
00364                                                         static char faceid[256];
00365                                                         switch (loop) 
00366                                                         {
00367                                                         case 1:// second token is the node_id 
00368                                                                 printf ("  Facial id: %s\n", tmpid);
00369                                                                 strncpy(faceid,tmpid,sizeof(faceid));
00370                                                                 break;
00371                                                         case 2: //third token is the TYPE
00372                                                                 if (!strcmp(tmpid,"FACIAL")) //only process if type is FACIAL
00373                                                                 {
00374                                                                         int c = 0;
00377                                                                         bool blink[10]; 
00378                                                                         float smile[10], frown[10], o[10], e[10], p[10];
00379                                                                         int count = getFacialData(iddata,nodes,blink,smile,frown,o,e,p);
00380                                                                         for (nodeid = strtok (nodes, ","); nodeid != NULL;
00381                                                                            nodeid = strtok (nodeid + strlen (nodeid) + 1, ","))
00382                                                                         {
00383                                                                                 printf("   %s - %d,%.3f,%.3f,%.3f,%.3f,%.3f\n",nodeid,blink[c],smile[c],frown[c],o[c],e[c],p[c]);
00384                                                                                 c++;
00385                                                                         }
00389                                                                         bool blink1=0; 
00390                                                                         float smile1=0.f, frown1=0.f, o1=0.f, e1=0.f, p1=0.f;
00391                                                                         if (getFacialSpecificData(iddata,faceid,&blink1,&smile1,&frown1,&o1,&e1,&p1))
00392                                                                                 printf("   Specific data for %s: %d,%.3f,%.3f,%.3f,%.3f,%.3f\n",faceid,blink1,smile1,frown1,o1,e1,p1);
00393                                                                 } else 
00394                                                                         printf("   Not FACIAL\n");
00395                                                                 break;
00396                                                         }
00397                                                         loop++;
00398                                                 }
00399                                                 loop=0;
00400                                         }
00401                                 }
00402                         }
00403                         if (ch=='1')
00404                         {
00410                                 char connectedclients[1024];
00411                                 char *guid, *node, *tmpid, *nodeid;
00412                                 char allnodes[2048], node_info[256];
00413                                 int loop = 0;
00414                                 char nodes[512];
00415                                 float data[7] = {0.f};
00416                                 printf("number of connected clients %i\n",getPeersID(connectedclients));
00417                                 //printf("connected clients (getPeersID): %s\n",connectedclients);
00418                                 for (guid = strtok (connectedclients, ";"); guid != NULL;
00419                                    guid = strtok (guid + strlen (guid) + 1, ";"))
00420                                 {
00421                                         strncpy (iddata, guid, sizeof (iddata));
00422                                         printf ("GUID: %s\n", iddata);
00426                                         printf("Number of nodes %i\n",getNodesInfo(iddata,allnodes));
00427                                         for (node = strtok (allnodes, ";"); node != NULL;
00428                                            node = strtok (node + strlen (node) + 1, ";"))
00429                                         {
00430                                                 strncpy (node_info, node, sizeof (node_info));
00431                                                 printf (" Node: %s\n", node_info);
00432                                                 for (tmpid = strtok (node_info, ","); tmpid != NULL;
00433                                                    tmpid = strtok (tmpid + strlen (tmpid) + 1, ","))
00434                                                 {
00435                                                         static char audioid[256];
00436                                                         switch (loop) 
00437                                                         {
00438                                                         case 1:// second token is the node_id 
00439                                                                 printf ("  Audio id: %s\n", tmpid);
00440                                                                 strncpy(audioid,tmpid,sizeof(audioid));
00441                                                                 break;
00442                                                         case 2: //third token is the TYPE
00443                                                                 if (!strcmp(tmpid,"AUDIO")) //only process if type is AUDIO
00444                                                                 {
00445                                                                         int c = 0;
00448                                                                         char audioserver[32], url[256], config[128];
00449                                                                         int audioport; 
00450                                                                         /*int count = getAudioData(iddata,nodes,audioserver,audioport,url,config);
00451                                                                         for (nodeid = strtok (nodes, ","); nodeid != NULL;
00452                                                                            nodeid = strtok (nodeid + strlen (nodeid) + 1, ","))
00453                                                                         {
00454                                                                                 printf("   %s - %s,%s,%d,%s,%s\n",nodeid,audioserver,audioport[c],url,config);
00455                                                                                 c++;
00456                                                                         }
00460                                                                         if (getAudioSpecificData(iddata,audioid,audioserver,&audioport,url,config))
00461                                                                                 printf("   Specific data for %s: %s,%d,%s,%s\n",audioid,audioserver,audioport,url,config);
00462                                                                 } else 
00463                                                                         printf("   Not AUDIO\n");
00464                                                                 break;
00465                                                         }
00466                                                         loop++;
00467                                                 }
00468                                                 loop=0;
00469                                         }
00470                                 }
00471                         }
00472                         if (ch=='2')
00473                         {
00479                                 char connectedclients[1024];
00480                                 char *guid, *node, *tmpid, *nodeid;
00481                                 char allnodes[2048], node_info[256];
00482                                 int loop = 0;
00483                                 char nodes[512];
00484                                 float data[7] = {0.f};
00485                                 printf("number of connected clients %i\n",getPeersID(connectedclients));
00486                                 //printf("connected clients (getPeersID): %s\n",connectedclients);
00487                                 for (guid = strtok (connectedclients, ";"); guid != NULL;
00488                                    guid = strtok (guid + strlen (guid) + 1, ";"))
00489                                 {
00490                                         strncpy (iddata, guid, sizeof (iddata));
00491                                         printf ("GUID: %s\n", iddata);
00495                                         printf("Number of nodes %i\n",getNodesInfo(iddata,allnodes));
00496                                         for (node = strtok (allnodes, ";"); node != NULL;
00497                                            node = strtok (node + strlen (node) + 1, ";"))
00498                                         {
00499                                                 strncpy (node_info, node, sizeof (node_info));
00500                                                 printf (" Node: %s\n", node_info);
00501                                                 for (tmpid = strtok (node_info, ","); tmpid != NULL;
00502                                                    tmpid = strtok (tmpid + strlen (tmpid) + 1, ","))
00503                                                 {
00504                                                         static char videoid[256];
00505                                                         switch (loop) 
00506                                                         {
00507                                                         case 1:// second token is the node_id 
00508                                                                 printf ("  Video id: %s\n", tmpid);
00509                                                                 strncpy(videoid,tmpid,sizeof(videoid));
00510                                                                 break;
00511                                                         case 2: //third token is the TYPE
00512                                                                 if (!strcmp(tmpid,"VIDEO")) //only process if type is VIDEO
00513                                                                 {
00514                                                                         int c = 0;
00517                                                                         char videoserver[32], url[256], config[128];
00518                                                                         int videoport, width, height = 0;
00519                                                                         double bandwidth;
00520                                                                         float calibration1[9], calibration2[16] = {0};
00521                                                                         /*int count = getVideoData(iddata,nodes,videoserver,videoport,url,frame_width,frame_height,bandwidth,calibration1,calibration2);
00522                                                                         for (nodeid = strtok (nodes, ","); nodeid != NULL;
00523                                                                            nodeid = strtok (nodeid + strlen (nodeid) + 1, ","))
00524                                                                         {
00525                                                                                 printf("   %s - %s,%s,%d,%s,%s\n",nodeid,videoserver,videoport[c],url,frame_width,frame_height,bandwidth,calibration1,calibration2);
00526                                                                                 c++;
00527                                                                         }
00531                                                                         if (getVideoSpecificData(iddata,videoid,videoserver,&videoport,url,&width,&height,&bandwidth,calibration1,calibration2))
00532                                                                                 printf("   Specific data for %s: %s,%d,%s,%d,%d,%.3f,%.3f,%.3f\n",videoid,videoserver,videoport,url,width,height,bandwidth,calibration1[0],calibration2[0]);
00533                                                                 } else 
00534                                                                         printf("   Not VIDEO\n");
00535                                                                 break;
00536                                                         }
00537                                                         loop++;
00538                                                 }
00539                                                 loop=0;
00540                                         }
00541                                 }
00542                         }
00543                 }
00544         }
00548         removeAllNodes();
00549         stop();
00550         exitlibrary();
00551 }
 All Classes Files Functions Variables Enumerations Enumerator Defines