Index: branches/FEPSimulator/FEPSim.h
===================================================================
--- branches/FEPSimulator/FEPSim.h	(revision 82)
+++ branches/FEPSimulator/FEPSim.h	(revision 84)
@@ -40,23 +40,24 @@
 const int BUFF_SIZE = 1000000;
 
-class FEPSim
-{
-	public:
-        /* members */
-		CLIENT *clnt; // RPC Client
+class FEPSim {
+public:
+    /* members */
+    CLIENT *clnt; // RPC Client
 
-        /* methods */
-		FEPSim(char * host, char * networkFile); // Constructor
-		~FEPSim(); // Destructor
+    /* methods */
+    FEPSim(char * ATMSHost); // Constructor
+    
+    void updateATMS(char * xml); // updates ATMS
 
-	private:
-        /* members */
-        NetworkReader *networkReader;
-        char * ATMSHost;
-        
-        /* methods */
-        void handleCallResponse(void *response); //
-        void createClient(char *host);
-        void updateATMS(); // updates ATMS
+    ~FEPSim(); // Destructor
+
+private:
+    /* members */
+    char * ATMSHost;
+
+    /* methods */
+    void handleCallResponse(void *response); //
+    bool createClient(char *host);
+    void sendReplys(char * xml);
 
 };
Index: branches/FEPSimulator/NetworkReader.cpp
===================================================================
--- branches/FEPSimulator/NetworkReader.cpp	(revision 82)
+++ branches/FEPSimulator/NetworkReader.cpp	(revision 84)
@@ -15,5 +15,4 @@
         TiXmlElement *subLoopElem = loopElem->FirstChildElement();
         loop->loopID = atoi(subLoopElem->GetText());
-        cout << "LOOPID: " << subLoopElem->GetText() << endl;
         subLoopElem = subLoopElem->NextSiblingElement();
         loop->loop_loc = (char *) subLoopElem->GetText();
@@ -40,4 +39,5 @@
     TiXmlElement *stationSubElem = stationElem->FirstChildElement();
     station->lds = atol(stationSubElem->GetText());
+    cout << "Station: " << station->lds << endl;
     line->lds.push_back(station->lds);
     line->ldsIndex.push_back(ldsIndex++);
@@ -63,5 +63,5 @@
         station->loops.push_back(loop);
     }
-
+    cout << "Number of Loops: " << station->loops.size() << endl;
     // Data pack ATMS message
     station->length = station->loops.size() * 2 + CONTROL_DATA_LEN;
Index: branches/FEPSimulator/FEPSim.cpp
===================================================================
--- branches/FEPSimulator/FEPSim.cpp	(revision 82)
+++ branches/FEPSimulator/FEPSim.cpp	(revision 84)
@@ -7,8 +7,6 @@
  * @param networkFile the xml network file
  */
-FEPSim::FEPSim(char * ATMShost, char * xml) {
-    networkReader = new NetworkReader(xml);
+FEPSim::FEPSim(char * ATMShost) {
     this->ATMSHost = ATMShost;
-    updateATMS();
 }
 
@@ -26,8 +24,9 @@
  */
 void FEPSim::handleCallResponse(void *response) {
-    /* If ATMS reply call fails */
+    // Failed RPC Call
     if (response == NULL) {
         clnt_perror(clnt, "RPC call failed");
-    }/* If ATMS reply is successful */
+    }
+    // Successful RPC Call
     else {
         cout << "Successful RPC call to ATMS..." << endl;
@@ -35,15 +34,12 @@
 }
 
-/**
- * Sends an fep_reply for every line in the FEP.
- */
-void FEPSim::updateATMS() {
-    int i, j; // i == line_index, j == lds_index
-    void *rv;
-    vector<FEP_LINE*> lines = networkReader->getLines();
-    vector<STATION*> ldsMap = networkReader->getStations();
-
-    // Send one reply for every "line" in the FEP
-    for (i = 0; i < lines.size(); i++) {
+void FEPSim::sendReplys(char * xml)
+{
+    NetworkReader networkReader = NetworkReader(xml);
+    vector<FEP_LINE*> lines = networkReader.getLines();
+    vector<STATION*> ldsMap = networkReader.getStations();
+    
+    // Send one reply for every FEPLine
+    for (int i = 0; i < lines.size(); i++) {
         fep_reply fepReply;
         cout << "Sending fepReply for line #" << lines.at(i)->lineNum << endl;
@@ -56,5 +52,6 @@
 
         /***********************************
-                 This is an update to an extern, this should happen on the Java driver side??
+         * We might need to handle this on the java side if its an
+         * issue
         lines.at(i).schedleSeq += 1;
         lines.at(i).globalSeq += 51;
@@ -63,9 +60,6 @@
         fepReply.schedule_sequence = lines.at(i)->schedleSeq;
         fepReply.global_sequence = lines.at(i)->globalSeq;
-        /************************************
-                 Need to find out what appropriate schedule time is: look at uci_unix_simulation_time src code
-        fepReply.schedule_time =
-                uci_unix_simulation_time(uci_simulation_time());	// GMT time
-         */
+
+        // using current unix time, may need to look at later
         fepReply.schedule_time = time(NULL);
 
@@ -77,6 +71,6 @@
         fepReply.answers.fep_answer_list_u.shortp.count = 1;
 
-        /* for each LDS in the Line.... (constructs the short_answer message) */
-        for (j = 0; j < lines.at(i)->lds.size(); j++) {
+        // construct a shortanswer for each station in line
+        for (int j = 0; j < lines.at(i)->lds.size(); j++) {
             fep_shortanswer fsa;
             int index = lines.at(i)->ldsIndex.at(j);
@@ -90,12 +84,8 @@
             int aa = ldsMap.at(index)->length;
             fsa.msg.message[2 + aa] = 0x0d;
-            fsa.msg.message[3 + aa] = 0xff; //????????????? warning ?????
+            fsa.msg.message[3 + aa] = 0xff;
 
             // info
             fsa.info.poll_error_count = 0;
-            /***************************************
-                     Need to find out polltime uci time function src code
-            fsa.info.poll_time = uci_unix_simulation_time(uci_simulation_time());
-             */
             fsa.info.poll_user_info1 = ldsMap.at(index)->drop; // drop number
             fsa.info.poll_user_info2 = 1; //always 1
@@ -103,15 +93,22 @@
             fsa.info.status = (enum replystatus) 1;
 
-            //fepReply.answers.fep_answer_list_u.shortp.answers[j +1] = fsa;
             fepReply.answers.fep_answer_list_u.shortp.answers[0] = fsa;
 
             // send out data
             printf("Transferring line=%d, lds_drop_no=%d...\n", lines.at(i)->lineNum, ldsMap.at(index)->drop);
-            rv = fep_reply_xfer_32(&fepReply, clnt);
-
-            /* Handle ATMS response to RPC Call */
+            // Make RPC Call and handle response
             printf("Handling ATMS response...\n");
-            handleCallResponse(rv);
-        }
+            handleCallResponse(fep_reply_xfer_32(&fepReply, clnt));
+        }
+    }
+}
+
+/**
+ * Sends an fep_reply for every line in the FEP.
+ */
+void FEPSim::updateATMS(char * xml) {
+    if(createClient(this->ATMSHost))
+    {
+        sendReplys(xml);
     }
 }
@@ -121,14 +118,18 @@
  * @param host rpc server ip
  */
-void FEPSim::createClient(char * host) {
+bool FEPSim::createClient(char * host) {
     /* Create RPC Client to communicate with ATMS */
+    bool success = true;
     cout << "Creating RPC Client" << endl;
     clnt = clnt_create(host, /*100090,*/ 103121, 32, "tcp");
-    cout << "Client created" << endl;
     /* Check if client creation failed */
     if (clnt == (CLIENT *) NULL) {
         cerr << "Can't create client to " << host << endl;
-        exit(1);
-    }
+        success = false;
+    }
+    else {
+        cout << "Client created" << endl;
+    }
+    return success;
 }
 
@@ -140,11 +141,16 @@
  */
 int main(int argc, char *argv[]) {
-
+    if(argc != 3)
+    {
+        cerr << "Usage: FEPSim <ATMS_Host> <FEP_ATMSDriver_PortNo" << endl;
+        exit(1);
+    }
+    char *FEPSimHost = argv[1];    
+    FEPSim fep = FEPSim(FEPSimHost);
+    
     int sockfd, newsockfd, portno, clilen;
     char buffer[BUFF_SIZE];
     struct sockaddr_in serv_addr, cli_addr;
     int n;
-    
-    char *FEPSimHost = argv[1];
     portno = atoi(argv[2]);
 
@@ -177,5 +183,5 @@
     clilen = sizeof (cli_addr);
 
-    /* Accept actual connection from the client */
+    /* Accept actual connections from the client */
     while(1) {
         newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
@@ -187,9 +193,13 @@
 
         /* If connection is established then start communicating */
+        // zero out buffer
         bzero(buffer, BUFF_SIZE);
         
-        // NEEDS OUTER LOOP TO GET WHOLE MESSAGE FROM TCP CONN
-        n = read(newsockfd, buffer, sizeof(buffer));
-
+        // read XML from socket
+        int totBytes = 0;
+        while ((n = recv(newsockfd, &buffer[totBytes], sizeof(buffer), 0)) > 0) {
+            totBytes += n;
+        }
+        
         if (n < 0) {
             perror("ERROR reading from socket");
@@ -197,8 +207,6 @@
         }
         
-        /* Create RPC Client to send an fep_reply to ATMS */
-
-        FEPSim *client = new FEPSim(FEPSimHost, buffer);
-        delete client;
+        // send data to atms
+        fep.updateATMS(buffer);
     }
 
