Index: vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp
===================================================================
--- vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 80)
+++ vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 81)
@@ -217,23 +217,21 @@
 }
 
-int ReceiveMessage(int socketfd, string message) {
-	
-	char buffer[256];
-	int n;
-
-	// Clear incoming data buffer
-    	bzero(buffer,256);
+
+int ReceiveMessage(int socket,char * buffer) 
+{
+    int i,n;
     
-	// Wait for incoming message
-	n = read(socketfd,buffer,256);
-	
-	// Print message
-    	if (n > 0) 
-        	printf("Here is the received meessage: %s\n",buffer);
-    	if(n == 0)
-        	printf("Client closed the socket.\n");
-	
-    	return n;
-}
+    n = recv(socket,buffer,256,MSG_PEEK);
+    for(i=0;i<256;i++){
+        if(strcmp(&buffer[i],"\0") == 0) break;
+    }
+    n = recv(socket,buffer,i+1,0);
+    if (n < 0)
+        error("ERROR reading from socket");
+    //    printf("ReadMessage:%s %d\n",buffer,n);
+
+    return n;
+}
+
 
 int SendMessage(int socketfd, string message) {
@@ -323,7 +321,9 @@
 	printf("Configuration sent, waiting for ACK...\n");
 	// Receive ACK for utils
+    char buffer[256];
         string message;
-	n = ReceiveMessage(socketfd, message);
-        cout << message << endl;
+	n = ReceiveMessage(socketfd, buffer);
+    printf("%s\n", buffer);
+        //cout << message << endl;
 	printf("ACK received.\n");
 
@@ -358,6 +358,6 @@
         CE_Info *ce_info)
 {
+    string message;
     char buffer[256];
-    string message;
     int i;
     float var;
@@ -365,54 +365,35 @@
     // utility
     // numUtilities
-    bzero(buffer,256);
-    message.erase();
-    ReceiveMessage(sockfd,message);
-    ce_info->numUtilities = atoi(message.c_str());
-    printf("number of utilities: %d\n", ce_info->numUtilities);
     for (i = 0; i < ce_info->numUtilities; i++){
         bzero(buffer,256);
-        message.erase();
-        ReceiveMessage(sockfd,message);
-        var = atof(message.c_str());
+        ReceiveMessage(sockfd,buffer);
+        var = atof(buffer);
         uList[i]->value = var;
-        printf("utility %s, value: %f\n", 
-                uList[i]->name, uList[i]->value);
+        printf("utility %s, value %f\n"
+                , uList[i]->name.c_str(), uList[i]->value);
     }
     
     // paramter
     // numparameters
-    /*bzero(buffer,256);*/
-    message.erase();
-    ReceiveMessage(sockfd,message);
-    ce_info->numParameters = atoi(message.c_str());
-    printf("number of parameters: %d\n", ce_info->numParameters);
     for (i = 0; i < ce_info->numParameters; i++){
-        /*bzero(buffer,256);*/
-        message.erase();
-        ReceiveMessage(sockfd,message);
-        var = atof(message.c_str());
+        bzero(buffer,256);
+        ReceiveMessage(sockfd,buffer);
+        var = atof(buffer);
         pList[i]->value = var;
-        printf("parameter %s, value: %f\n", 
-                pList[i]->name, pList[i]->value);
+        printf("parameter %s, value %f\n"
+                , pList[i]->name.c_str(), pList[i]->value);
     }
 
     // observable
     // numObservables
-    /*bzero(buffer,256);
-    ReceiveMessage(sockfd,buffer);*/
-    message.erase();
-    ReceiveMessage(sockfd,message);
-    ce_info->numObservables = atoi(message.c_str());
-    printf("number of observables: %d\n", ce_info->numObservables);
     for (i = 0; i < ce_info->numObservables; i++){
-        /*bzero(buffer,256);
-        ReceiveMessage(sockfd,buffer);*/
-        message.erase();
-        ReceiveMessage(sockfd,message);
-        var = atof(message.c_str());
+        bzero(buffer,256);
+        ReceiveMessage(sockfd,buffer);
+        var = atof(buffer);
         oList[i]->value = var;
-        printf("observable %s, value: %f\n", 
-                oList[i]->name, oList[i]->value);
+        printf("observable %s, value %f\n"
+                , oList[i]->name.c_str(), oList[i]->value);
     }
+    return 1;
 }
 
