Index: /trunk/src/atmsdriver/NetworkLoader.java
===================================================================
--- /trunk/src/atmsdriver/NetworkLoader.java	(revision 79)
+++ /trunk/src/atmsdriver/NetworkLoader.java	(revision 84)
@@ -2,7 +2,7 @@
 
 import atmsdriver.model.FEPLine;
-import atmsdriver.model.LoopDetectorStation;
+import atmsdriver.model.Station;
 import atmsdriver.model.LoopDetector;
-import atmsdriver.model.LoopDetectorStation.DIRECTION;
+import atmsdriver.model.Station.DIRECTION;
 import java.io.File;
 import java.io.FileNotFoundException;
@@ -17,10 +17,10 @@
  * 
  *  The public method getFEPLines() method can be used to get all the FEPLines 
- *  within a network. All other methods are private and are used to construct
- *  the FEPLines.
- * 
- *  The "LDSFile" contains LoopDetectorStation and FEPLine information.
- *  ex.
- *   < Insert file here >
+  within a network. All other methods are private and are used to construct
+  the FEPLines.
+ 
+  The "LDSFile" contains Station and FEPLine information.
+  ex.
+   < Insert file here >
  *  The "loopFile" contains individual LoopDetector information.
  *  ex.
@@ -157,5 +157,5 @@
                 
                 // Create each Station for the current FEPLine
-                ArrayList<LoopDetectorStation> stns = new ArrayList<>();
+                ArrayList<Station> stns = new ArrayList<>();
                 for(Integer stnNum : stnNums)
                 {
@@ -165,5 +165,5 @@
                     
                     // Create the Station and add to list for curr FEPLine
-                    LoopDetectorStation stn =
+                    Station stn =
                             createStation(stnNum, new Scanner(LDSFile), loops);
                     stns.add(stn);
@@ -181,5 +181,5 @@
     
     // Creates  line
-    private FEPLine createLine(int lineNum, Scanner scLine, ArrayList<LoopDetectorStation> stns)
+    private FEPLine createLine(int lineNum, Scanner scLine, ArrayList<Station> stns)
     {
         FEPLine line = null;
@@ -239,7 +239,7 @@
     
     // creates a Station
-    private LoopDetectorStation createStation(int stnNum, Scanner sc, ArrayList<LoopDetector> detectors)
-    {
-        LoopDetectorStation LDS = null;
+    private Station createStation(int stnNum, Scanner sc, ArrayList<LoopDetector> detectors)
+    {
+        Station LDS = null;
         
         sc.nextLine();
@@ -264,5 +264,5 @@
                 double postmile = scLine.nextDouble();
                 String ldsName = getLocation(strLine); /************* DOESNT GRAB WHOLE???? */////
-                LDS = new LoopDetectorStation(lineNum, ldsID, drop, ldsName, detectors, fwy, dir, postmile);
+                LDS = new Station(lineNum, ldsID, drop, ldsName, detectors, fwy, dir, postmile);
                 
                 break;
Index: /trunk/src/atmsdriver/model/Station.java
===================================================================
--- /trunk/src/atmsdriver/model/Station.java	(revision 84)
+++ /trunk/src/atmsdriver/model/Station.java	(revision 84)
@@ -0,0 +1,173 @@
+package atmsdriver.model;
+
+import java.util.List;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/** A Station is a simulation of a station in a traffic network.
+ *  
+ *  A Station (LDS) contains static meta data about the station, and
+  two dynamic attributes, MLTotVol and OppTotVol. 
+ 
+  A single LDS contains multiple LoopDetectors, which
+  contain data for a single lane on one direction of the freeway. A LDS
+  is specific to a single freeway, direction, and postmile.
+ *
+ * @author John A. Torres
+ * @version 9/10/2017
+ */
+public class Station implements Comparable {
+    /* Static Station meta data */
+    final private int lineNum;
+    final private int ldsID; // double check
+    final private int drop;
+    final private String location;
+    final private List<LoopDetector> loops;
+    final private int freeway;
+    final private double postmile;
+    final private DIRECTION direction;
+    
+    /* Dynamic Station data */
+    private int MLTotVol;
+    private int OppTotVol;
+    
+    /* Constructor */
+    public Station(int lineNum, int ldsID, int drop,
+            String location, List<LoopDetector> loops, int fwy, 
+            DIRECTION direction, double postmile)
+    {
+        this.lineNum = lineNum;
+        this.ldsID = ldsID;
+        this.drop = drop;
+        this.loops = loops;
+        this.location = location;
+        this.postmile = postmile;
+        this.direction = direction;
+        this.freeway = fwy;
+        
+        this.MLTotVol = 0;
+        this.OppTotVol = 0;
+    }
+
+    @Override
+    public int compareTo(Object o) {
+        
+    }
+    
+    private static enum XML_TAGS
+    {
+        STATION("Station"),
+        LDS_ID("LDS_ID"),
+        LINE_NUM("Line_Num"),
+        DROP("Drop"),
+        LOOPS("Loops"),
+        LOCATION("Location"),
+        POST_MILE("Post_Mile"),
+        DIRECTION("Direction"),
+        FREEWAY("Freeway"),
+        ML_TOT_VOL("ML_Tot_Vol"),
+        OPP_TOT_VOL("Opp_Tot_Vol");
+        
+        String tag;
+        
+        private XML_TAGS(String n)
+        {
+            tag = n;
+        }
+    }
+    
+    public void toXML(Element currElem)
+    {
+        Document theDoc = currElem.getOwnerDocument();
+        
+        Element stationElement = theDoc.createElement(XML_TAGS.STATION.tag);
+        currElem.appendChild(stationElement);
+        
+        Element ldsIDElement = theDoc.createElement(XML_TAGS.LDS_ID.tag);
+        ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.ldsID)));
+        stationElement.appendChild(ldsIDElement);
+        
+        Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag);
+        lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum)));
+        stationElement.appendChild(lineNumElement);
+        
+        Element dropElement = theDoc.createElement(XML_TAGS.DROP.tag);
+        dropElement.appendChild(theDoc.createTextNode(String.valueOf(this.drop)));
+        stationElement.appendChild(dropElement);
+        
+        Element locationElement = theDoc.createElement(XML_TAGS.LOCATION.tag);
+        locationElement.appendChild(theDoc.createTextNode(this.location));
+        stationElement.appendChild(locationElement);
+        
+        Element postMileElement = theDoc.createElement(XML_TAGS.POST_MILE.tag);
+        postMileElement.appendChild(theDoc.createTextNode(String.valueOf(this.postmile)));
+        stationElement.appendChild(postMileElement);
+        
+        Element directionElement = theDoc.createElement(XML_TAGS.DIRECTION.tag);
+        directionElement.appendChild(theDoc.createTextNode(this.direction.name));
+        stationElement.appendChild(directionElement);
+        
+        Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag);
+        freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.freeway)));
+        stationElement.appendChild(freewayElement);
+        
+        Element mlElement = theDoc.createElement(XML_TAGS.ML_TOT_VOL.tag);
+        mlElement.appendChild(theDoc.createTextNode(String.valueOf(this.MLTotVol)));
+        stationElement.appendChild(mlElement);
+        
+        Element oppElement = theDoc.createElement(XML_TAGS.OPP_TOT_VOL.tag);
+        oppElement.appendChild(theDoc.createTextNode(String.valueOf(this.OppTotVol)));
+        stationElement.appendChild(oppElement);
+        
+        Element loopsElement = theDoc.createElement(XML_TAGS.LOOPS.tag);
+        stationElement.appendChild(loopsElement);
+        
+        for(LoopDetector loop : loops)
+        {
+            loop.toXML(loopsElement);
+        }
+    }
+    
+    /**
+     * Enum for freeway direction.
+     * 
+     * @author John A. Torres
+     * @version 9/10/2017
+     */
+    public static enum DIRECTION
+    {
+        NORTH("N"),
+        SOUTH("S"),
+        EAST("E"),
+        WEST("W");
+        
+        String name;
+        
+        DIRECTION(String name)
+        {
+            this.name = name;
+        }
+        
+        /**
+         * Returns the direction enum, given a string value.
+         * @param name str value for enum
+         * @return enum for given str value
+         */
+        public static DIRECTION getEnum(String name)
+        {
+            switch(name)
+            {
+                case "S":
+                    return SOUTH;
+                case "N":
+                    return NORTH;
+                case "E":
+                    return EAST;
+                case "W":
+                    return WEST;
+                default:
+                    return null;
+            }
+        }
+    }
+}
Index: /trunk/src/atmsdriver/model/FEPLine.java
===================================================================
--- /trunk/src/atmsdriver/model/FEPLine.java	(revision 79)
+++ /trunk/src/atmsdriver/model/FEPLine.java	(revision 84)
@@ -19,5 +19,5 @@
     /* Static FEPLine meta data */
     final private int lineNum;
-    final private List<LoopDetectorStation> stations;
+    final private List<Station> stations;
     final private int count;
     // NOT SURE IF NEXT IS FINAL
@@ -28,5 +28,5 @@
     final private long scheduleSeq;
     
-    public FEPLine(int lineNum, List<LoopDetectorStation> stations, int count,
+    public FEPLine(int lineNum, List<Station> stations, int count,
             int schedule, int lineInfo, long systemKey, long globalSeq,
             long scheduleSeq)
@@ -79,5 +79,5 @@
         Element stationsElement = theDoc.createElement(XML_TAGS.STATIONS.tag);
         lineElement.appendChild(stationsElement);
-        for(LoopDetectorStation station : stations)
+        for(Station station : stations)
         {
             station.toXML(stationsElement);
Index: unk/src/atmsdriver/model/LoopDetectorStation.java
===================================================================
--- /trunk/src/atmsdriver/model/LoopDetectorStation.java	(revision 79)
+++ 	(revision )
@@ -1,168 +1,0 @@
-package atmsdriver.model;
-
-import java.util.List;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-/** A LoopDetectorStation is a simulation of a station in a traffic network.
- *  
- *  A LoopDetectorStation (LDS) contains static meta data about the station, and
- *  two dynamic attributes, MLTotVol and OppTotVol. 
- * 
- *  A single LDS contains multiple LoopDetectors, which
- *  contain data for a single lane on one direction of the freeway. A LDS
- *  is specific to a single freeway, direction, and postmile.
- *
- * @author John A. Torres
- * @version 9/10/2017
- */
-public class LoopDetectorStation {
-    /* Static LoopDetectorStation meta data */
-    final private int lineNum;
-    final private int ldsID; // double check
-    final private int drop;
-    final private String location;
-    final private List<LoopDetector> loops;
-    final private int freeway;
-    final private double postmile;
-    final private DIRECTION direction;
-    
-    /* Dynamic LoopDetectorStation data */
-    private int MLTotVol;
-    private int OppTotVol;
-    
-    /* Constructor */
-    public LoopDetectorStation(int lineNum, int ldsID, int drop,
-            String location, List<LoopDetector> loops, int fwy, 
-            DIRECTION direction, double postmile)
-    {
-        this.lineNum = lineNum;
-        this.ldsID = ldsID;
-        this.drop = drop;
-        this.loops = loops;
-        this.location = location;
-        this.postmile = postmile;
-        this.direction = direction;
-        this.freeway = fwy;
-        
-        this.MLTotVol = 0;
-        this.OppTotVol = 0;
-    }
-    
-    private static enum XML_TAGS
-    {
-        STATION("Station"),
-        LDS_ID("LDS_ID"),
-        LINE_NUM("Line_Num"),
-        DROP("Drop"),
-        LOOPS("Loops"),
-        LOCATION("Location"),
-        POST_MILE("Post_Mile"),
-        DIRECTION("Direction"),
-        FREEWAY("Freeway"),
-        ML_TOT_VOL("ML_Tot_Vol"),
-        OPP_TOT_VOL("Opp_Tot_Vol");
-        
-        String tag;
-        
-        private XML_TAGS(String n)
-        {
-            tag = n;
-        }
-    }
-    
-    public void toXML(Element currElem)
-    {
-        Document theDoc = currElem.getOwnerDocument();
-        
-        Element stationElement = theDoc.createElement(XML_TAGS.STATION.tag);
-        currElem.appendChild(stationElement);
-        
-        Element ldsIDElement = theDoc.createElement(XML_TAGS.LDS_ID.tag);
-        ldsIDElement.appendChild(theDoc.createTextNode(String.valueOf(this.ldsID)));
-        stationElement.appendChild(ldsIDElement);
-        
-        Element lineNumElement = theDoc.createElement(XML_TAGS.LINE_NUM.tag);
-        lineNumElement.appendChild(theDoc.createTextNode(String.valueOf(this.lineNum)));
-        stationElement.appendChild(lineNumElement);
-        
-        Element dropElement = theDoc.createElement(XML_TAGS.DROP.tag);
-        dropElement.appendChild(theDoc.createTextNode(String.valueOf(this.drop)));
-        stationElement.appendChild(dropElement);
-        
-        Element locationElement = theDoc.createElement(XML_TAGS.LOCATION.tag);
-        locationElement.appendChild(theDoc.createTextNode(this.location));
-        stationElement.appendChild(locationElement);
-        
-        Element postMileElement = theDoc.createElement(XML_TAGS.POST_MILE.tag);
-        postMileElement.appendChild(theDoc.createTextNode(String.valueOf(this.postmile)));
-        stationElement.appendChild(postMileElement);
-        
-        Element directionElement = theDoc.createElement(XML_TAGS.DIRECTION.tag);
-        directionElement.appendChild(theDoc.createTextNode(this.direction.name));
-        stationElement.appendChild(directionElement);
-        
-        Element freewayElement = theDoc.createElement(XML_TAGS.FREEWAY.tag);
-        freewayElement.appendChild(theDoc.createTextNode(String.valueOf(this.freeway)));
-        stationElement.appendChild(freewayElement);
-        
-        Element mlElement = theDoc.createElement(XML_TAGS.ML_TOT_VOL.tag);
-        mlElement.appendChild(theDoc.createTextNode(String.valueOf(this.MLTotVol)));
-        stationElement.appendChild(mlElement);
-        
-        Element oppElement = theDoc.createElement(XML_TAGS.OPP_TOT_VOL.tag);
-        oppElement.appendChild(theDoc.createTextNode(String.valueOf(this.OppTotVol)));
-        stationElement.appendChild(oppElement);
-        
-        Element loopsElement = theDoc.createElement(XML_TAGS.LOOPS.tag);
-        stationElement.appendChild(loopsElement);
-        
-        for(LoopDetector loop : loops)
-        {
-            loop.toXML(loopsElement);
-        }
-    }
-    
-    /**
-     * Enum for freeway direction.
-     * 
-     * @author John A. Torres
-     * @version 9/10/2017
-     */
-    public static enum DIRECTION
-    {
-        NORTH("N"),
-        SOUTH("S"),
-        EAST("E"),
-        WEST("W");
-        
-        String name;
-        
-        DIRECTION(String name)
-        {
-            this.name = name;
-        }
-        
-        /**
-         * Returns the direction enum, given a string value.
-         * @param name str value for enum
-         * @return enum for given str value
-         */
-        public static DIRECTION getEnum(String name)
-        {
-            switch(name)
-            {
-                case "S":
-                    return SOUTH;
-                case "N":
-                    return NORTH;
-                case "E":
-                    return EAST;
-                case "W":
-                    return WEST;
-                default:
-                    return null;
-            }
-        }
-    }
-}
Index: /trunk/config/atms_driver_config.properties
===================================================================
--- /trunk/config/atms_driver_config.properties	(revision 79)
+++ /trunk/config/atms_driver_config.properties	(revision 84)
@@ -3,2 +3,4 @@
 NetworkFileName = networkFile.txt
 ExchangeFileName = exchange.xml
+FEPWriterHost = localhost
+FEPWriterPort = 8080
Index: /branches/trunk/IDE_metadata/NetBeans/TMCSim/build/built-jar.properties
===================================================================
--- /branches/trunk/IDE_metadata/NetBeans/TMCSim/build/built-jar.properties	(revision 82)
+++ /branches/trunk/IDE_metadata/NetBeans/TMCSim/build/built-jar.properties	(revision 84)
@@ -1,3 +1,3 @@
-#Fri, 06 Oct 2017 19:49:49 -0700
+#Sat, 07 Oct 2017 00:43:14 -0700
 
 
Index: /branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/tmcsim/application.properties
===================================================================
--- /branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/tmcsim/application.properties	(revision 82)
+++ /branches/trunk/IDE_metadata/NetBeans/TMCSim/build/classes/tmcsim/application.properties	(revision 84)
@@ -1,5 +1,5 @@
-#Fri, 06 Oct 2017 19:49:49 -0700
+#Sat, 07 Oct 2017 00:43:14 -0700
 
-Application.revision=0
+Application.revision=83
 
-Application.buildnumber=50
+Application.buildnumber=58
Index: /branches/trunk/src/tmcsim/application.properties
===================================================================
--- /branches/trunk/src/tmcsim/application.properties	(revision 82)
+++ /branches/trunk/src/tmcsim/application.properties	(revision 84)
@@ -1,5 +1,5 @@
-#Fri, 06 Oct 2017 19:49:49 -0700
+#Sat, 07 Oct 2017 00:43:14 -0700
 
-Application.revision=0
+Application.revision=83
 
-Application.buildnumber=50
+Application.buildnumber=58
Index: /branches/trunk/src/atmsdriver/ATMSDriver.java
===================================================================
--- /branches/trunk/src/atmsdriver/ATMSDriver.java	(revision 83)
+++ /branches/trunk/src/atmsdriver/ATMSDriver.java	(revision 84)
@@ -53,5 +53,5 @@
     
     /** Sleep Time (10 seconds). **/
-    private static final int SLEEP_TIME = 10000;
+    private static final int SLEEP_TIME = 30000;
     
     /** Exchange Reader */
Index: /branches/trunk/src/atmsdriver/NetworkLoader.java
===================================================================
--- /branches/trunk/src/atmsdriver/NetworkLoader.java	(revision 82)
+++ /branches/trunk/src/atmsdriver/NetworkLoader.java	(revision 84)
@@ -143,7 +143,5 @@
     private void constructFEPLines()
     {
-        try {
-            System.out.println("Building network...");
-            
+        try {            
             // Get FEPLine IDs
             ArrayList<Integer> lineNums = getLineNums(new Scanner(LDSFile));
Index: /branches/trunk/src/atmsdriver/model/HighwayStatusWriter.java
===================================================================
--- /branches/trunk/src/atmsdriver/model/HighwayStatusWriter.java	(revision 82)
+++ /branches/trunk/src/atmsdriver/model/HighwayStatusWriter.java	(revision 84)
@@ -31,5 +31,5 @@
         Socket sock = new Socket(host, port);
         PrintWriter out = new PrintWriter(sock.getOutputStream(), true);
-        out.print(xml);
+        out.println(xml);
         sock.close();
     }
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);
     }
 
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);
 
 };
