Machine Vision Status TCP Server

Dependencies:   C12832 EthernetInterface mbed-rtos mbed ConfigFile

Revision:
1:8efef658d90b
Child:
2:a8eebf64cd3e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TcpDaemon.h	Thu Mar 05 13:18:28 2015 +0000
@@ -0,0 +1,51 @@
+#include "EthernetInterface.h"
+
+#ifndef TCP_DAEMON_HEADER
+#define TCP_DAEMON_HEADER
+
+#define MAX_BACKLOG 1
+
+namespace MachineVision{
+    
+    class TcpDaemon{
+        public:
+            const static int BUFFER_SIZE = 512;
+            const static int TCP_TIMEOUT = 1000;
+
+        private:
+            int server_port;
+            TCPSocketServer server;
+            TCPSocketConnection client;
+
+            char buffer[BUFFER_SIZE+1];
+            bool keepListening;
+
+        public:
+            /*
+             * TcpDaemon constructor
+             *
+             * @server_port the port the daemon will be listening on
+             */
+            TcpDaemon(int server_port);
+
+            /*
+             * Make the daemon start listening for incoming connections
+             */
+            void startListening();
+
+        private:
+            /*
+             * Bind to server socket
+             *
+             * @return true on success
+             */
+            bool bindSocket();
+
+            /*
+             * Listen for incoming connections
+             */
+            void doListen();
+    };
+}
+
+#endif