Index: branches/FEPSimulator/FEPSim.cpp
===================================================================
--- branches/FEPSimulator/FEPClient.cpp	(revision 80)
+++ branches/FEPSimulator/FEPSim.cpp	(revision 82)
@@ -1,3 +1,3 @@
-#include "FEPClient.h"
+#include "FEPSim.h"
 
 /**
@@ -7,7 +7,7 @@
  * @param networkFile the xml network file
  */
-FEPClient::FEPClient(char * host, char * networkFile) {
-    networkReader = new NetworkReader(networkFile);
-    createClient(host);
+FEPSim::FEPSim(char * ATMShost, char * xml) {
+    networkReader = new NetworkReader(xml);
+    this->ATMSHost = ATMShost;
     updateATMS();
 }
@@ -16,5 +16,5 @@
  * Destructor
  */
-FEPClient::~FEPClient() {
+FEPSim::~FEPSim() {
     cout << "Destroying client..." << endl;
     clnt_destroy(clnt);
@@ -25,9 +25,9 @@
  * @param response pointer to fep_reply struct
  */
-void FEPClient::handleCallResponse(void *response) {
+void FEPSim::handleCallResponse(void *response) {
     /* If ATMS reply call fails */
     if (response == NULL) {
         clnt_perror(clnt, "RPC call failed");
-    }        /* If ATMS reply is successful */
+    }/* If ATMS reply is successful */
     else {
         cout << "Successful RPC call to ATMS..." << endl;
@@ -38,8 +38,7 @@
  * Sends an fep_reply for every line in the FEP.
  */
-void FEPClient::updateATMS() {
+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();
@@ -122,5 +121,5 @@
  * @param host rpc server ip
  */
-void FEPClient::createClient(char * host) {
+void FEPSim::createClient(char * host) {
     /* Create RPC Client to communicate with ATMS */
     cout << "Creating RPC Client" << endl;
@@ -142,18 +141,65 @@
 int main(int argc, char *argv[]) {
 
-    char *host;
-    char *networkFile;
-
-    if (argc < 3) {
-        cout << "usage:  " << argv[0] << " server_host networkFile" << endl;
+    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]);
+
+    /* First call to socket() function */
+    sockfd = socket(AF_INET, SOCK_STREAM, 0);
+
+    if (sockfd < 0) {
+        perror("ERROR opening socket");
         exit(1);
     }
 
-    /* Create RPC Client to send an fep_reply to ATMS */
-    host = argv[1];
-    networkFile = argv[2];
-
-    FEPClient *client = new FEPClient(host, networkFile);
-    delete client;
+    /* Initialize socket structure */
+    bzero((char *) &serv_addr, sizeof (serv_addr));
+
+    serv_addr.sin_family = AF_INET;
+    serv_addr.sin_addr.s_addr = INADDR_ANY;
+    serv_addr.sin_port = htons(portno);
+
+    /* Now bind the host address using bind() call.*/
+    if (bind(sockfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0) {
+        perror("ERROR on binding");
+        exit(1);
+    }
+
+    /* Now start listening for the clients, here process will
+     * go in sleep mode and will wait for the incoming connection
+     */
+
+    listen(sockfd, 5);
+    clilen = sizeof (cli_addr);
+
+    /* Accept actual connection from the client */
+    while(1) {
+        newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, (socklen_t *)&clilen);
+
+        if (newsockfd < 0) {
+            perror("ERROR on accept");
+            exit(1);
+        }
+
+        /* If connection is established then start communicating */
+        bzero(buffer, BUFF_SIZE);
+        
+        // NEEDS OUTER LOOP TO GET WHOLE MESSAGE FROM TCP CONN
+        n = read(newsockfd, buffer, sizeof(buffer));
+
+        if (n < 0) {
+            perror("ERROR reading from socket");
+            exit(1);
+        }
+        
+        /* Create RPC Client to send an fep_reply to ATMS */
+
+        FEPSim *client = new FEPSim(FEPSimHost, buffer);
+        delete client;
+    }
 
     return 0;
