Index: vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp
===================================================================
--- vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 64)
+++ vtcross/branches/trnewman/CR_shell/src/main_cognitive_radio.cpp	(revision 65)
@@ -7,4 +7,5 @@
 #include "socket/SocketException.h"
 
+
 using namespace std;
 
@@ -16,6 +17,4 @@
 	int numObservables;
 };
-
-
 
 struct Utility {
@@ -45,5 +44,5 @@
 };
 
-void print_current_config(Utility * uList[], Parameter * pList[10], Observable * oList[], CE_Info * ce_info) {
+void print_current_config(Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
 	int i = 0;
 	int j = 0;
@@ -216,30 +215,98 @@
 }
 
-void StartMessageParser( int socketfd) {
+int ReceiveMessage(int socketfd) {
+	
 	char buffer[256];
 	int n;
 
-	while(1) {
-		// Clear incoming data buffer
-     		bzero(buffer,256);
-     		
-		// Wait for incoming message
-		n = recv(socketfd,buffer,255,0);
-     		if (n < 0) error("ERROR reading from socket");
-     		if (n == 0) {
+	// Clear incoming data buffer
+     	bzero(buffer,256);
+    
+	// Wait for incoming message
+	n = recv(socketfd,buffer,255,0);
+	
+	// Print message
+     	if (n > 0) printf("Here is the message: %s\n",buffer);
+
+	return n;
+}
+
+int SendMessage(int socketfd, string message) {
+	int n;
+
+	// Write message back to client
+     	n = send(socketfd,message.c_str(),(message.size()+1),MSG_NOSIGNAL);
+	return n;
+
+}
+
+void StartMessaging(int socketfd,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
+	int n,i,j;
+	char counter[55];
+	char var[50];
+	int k;
+
+
+//	while(1) {
+		// Send parameters from struct
+		sprintf(counter,"%d",ce_info->numUtilities);
+		SendMessage(socketfd,counter);
+		
+ 		for(i = 0; i < ce_info->numUtilities ; i++) {
+			SendMessage(socketfd,uList[i]->name);
+			SendMessage(socketfd,uList[i]->units);
+			SendMessage(socketfd,uList[i]->goal);
+			sprintf(var,"%f",uList[i]->target);
+			SendMessage(socketfd,var);
+		}
+		sprintf(counter,"%i",ce_info->numParameters);
+		SendMessage(socketfd,counter);
+		for(i = 0; i < ce_info->numParameters; i++) {
+			SendMessage(socketfd,pList[i]->name);
+			SendMessage(socketfd,pList[i]->units);
+			sprintf(var,"%f",pList[i]->min);
+			SendMessage(socketfd,var);
+			sprintf(var,"%f",pList[i]->max);
+			SendMessage(socketfd,var);
+			sprintf(var,"%f",pList[i]->step);
+			SendMessage(socketfd,var);
+		
+			sprintf(counter,"%i",pList[i]->numAffects); 
+			SendMessage(socketfd,counter);
+			for(j = 0; j < pList[i]->numAffects; j++) {
+				SendMessage(socketfd,pList[i]->affection_list[j].u->name);
+				SendMessage(socketfd,pList[i]->affection_list[j].relation);
+			}
+		}
+		sprintf(counter,"%i",ce_info->numObservables);
+		SendMessage(socketfd,counter);
+		for(i = 0; i < ce_info->numObservables; i++) {
+			SendMessage(socketfd,oList[i]->name);
+			
+			sprintf(counter,"%i",oList[i]->numAffects); 
+			SendMessage(socketfd,counter);
+			for(j = 0; j < oList[i]->numAffects; j++) {
+				SendMessage(socketfd,oList[i]->affection_list[j].u->name);
+				SendMessage(socketfd,oList[i]->affection_list[j].relation);
+			}
+		}
+/*		
+
+		// Receive a message
+		n = ReceiveMessage(socketfd);	
+		if (n < 0) {
+			printf("ERROR reading from socket");
+			close(socketfd);
+     			return;
+		}
+		if (n == 0) {
 			printf("Client has closed the connection.\n");
 			return;
 		}
-		
-		// Print message
-     		printf("Here is the message: %s\n",buffer);
-
-		// Write message back to client
-     		n = write(socketfd,"I got your message",18);
-     		if (n < 0) error("ERROR writing to socket");
-	}
-}
-
-int StartShell(int port) {
+*/	
+//	}
+}
+
+int StartShell(int port,Utility * uList[], Parameter * pList[], Observable * oList[], CE_Info * ce_info) {
    	// Start socket server
      	int sockfd, newsockfd, clilen;
@@ -269,5 +336,5 @@
 
 		// Begin parsing the messages
-		StartMessageParser(newsockfd);
+		StartMessaging(newsockfd,uList, pList, oList, ce_info);
 	}
 	return 0;
@@ -309,8 +376,8 @@
 	if(pid == 0) {
 		// In child process - open policy engine port.
-		StartShell(30001);
+	//	StartShell(30003,uList, pList, oList, &ce_info);
 	} else {
 		// In parent process - open cognitive engine port.
-		StartShell(30000);
+		StartShell(30000,uList, pList, oList, &ce_info);
 	} 
 	
