Index: server/server.cpp
===================================================================
--- server/server.cpp	(revision 59061f6452ccd0881ef056346bd48a79f97c8395)
+++ server/server.cpp	(revision 87b3ee2526ba9b73d93862e48b4d519434148b39)
@@ -2,13 +2,16 @@
 
 #include <cstdlib>
+#include <cstdio>
 #include <unistd.h>
 #include <string>
-#include <netdb.h>
-#include <cstdio>
 #include <iostream>
 #include <vector>
 #include <algorithm>
 
+#include <fcntl.h>
+#include <assert.h>
+
 #include <sys/socket.h>
+#include <netdb.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
@@ -77,4 +80,12 @@
 }
 
+void set_nonblock(int sock)
+{
+    int flags;
+    flags = fcntl(sock, F_GETFL,0);
+    assert(flags != -1);
+    fcntl(sock, F_SETFL, flags | O_NONBLOCK);
+}
+
 int main(int argc, char *argv[])
 {
@@ -86,5 +97,6 @@
 
    srand(time(NULL));
-   int num = (rand() % 1000) + 1;
+   int num = 500;
+   //int num = (rand() % 0) + 1;
 
    cout << "num: " << num << endl;
@@ -99,4 +111,5 @@
    }
 
+   /*
    DataAccess da;
 
@@ -116,6 +129,7 @@
    da.printPlayers();
    cout << endl;
+   */
    
-   sock=socket(AF_INET, SOCK_DGRAM, 0);
+   sock = socket(AF_INET, SOCK_DGRAM, 0);
    if (sock < 0) error("Opening socket");
    length = sizeof(server);
@@ -127,18 +141,26 @@
       error("binding");
 
+   set_nonblock(sock);
+
    while (true) {
-      // if n == 0, means the client disconnected. may want to check this
+
+      usleep(5000);
+
       n = receiveMessage(&clientMsg, sock, &from);
-      if (n < 0)
-         error("recieveMessage");
-
-      processMessage(clientMsg, from, vctPlayers, num, serverMsg);
-
-      cout << "msg: " << serverMsg.buffer << endl;
-
-      n = sendMessage(&serverMsg, sock, &from);
-      if (n  < 0)
-         error("sendMessage");
-   }
+
+      if (n >= 0) {
+         cout << "Got a message" << endl;
+
+         processMessage(clientMsg, from, vctPlayers, num, serverMsg);
+
+         cout << "msg: " << serverMsg.buffer << endl;
+
+         n = sendMessage(&serverMsg, sock, &from);
+         if (n  < 0)
+            error("sendMessage");
+      }
+
+   }
+
    return 0;
 }
