--- /dev/null
+/*
+ * OpenDispense 2
+ * UCC (University [of WA] Computer Club) Electronic Accounting System
+ *
+ * server.c - Client Server Code
+ *
+ * This file is licenced under the 3-clause BSD Licence. See the file
+ * COPYING for full details.
+ */
+#include <stdio.h>
+#include <stdlib.h>
+#include "common.h"
+#include <sys/socket.h>
+
+#define MAX_CONNECTION_QUEUE 5
+#define INPUT_BUFFER_SIZE 100
+
+#define MSG_STR_TOO_LONG "499 Malformed Command String"
+
+// === GLOBALS ===
+ int giServer_Port = 1020;
+
+// === CODE ===
+void Server_Start(void)
+{
+ // Create Server
+}
+
+void Server_HandleClient(int Socket)
+{
+ char inbuf[INPUT_BUFFER_SIZE];
+ char *buf = inbuf;
+ int remspace = INPUT_BUFFER_SIZE-1;
+ int bytes = -1;
+
+ // Read from client
+ while( (bytes = recv(Socket, buf, remspace, 0)) > 0 )
+ {
+ char *eol, *start;
+ buf[bytes] = '\0'; // Allow us to use stdlib string functions on it
+
+ // Split by lines
+ start = inbuf;
+ while( (eol = strchr(start, '\n')) )
+ {
+ *eol = '\0';
+ Server_ParseClientCommand(Socket, start);
+ start = eol + 1;
+ }
+
+ // Check if there was an incomplete line
+ if( *start != '\0' ) {
+ int tailBytes = bytes - (start-buf);
+ // Roll back in buffer
+ memcpy(inbuf, start, tailBytes);
+ remspace -= tailBytes;
+ if(remspace == 0) {
+ send(Socket, MSG_STR_TOO_LONG, sizeof(MSG_STR_TOO_LONG));
+ }
+ }
+ else {
+ buf = inbuf;
+ remspace = INPUT_BUFFER_SIZE - 1;
+ }
+ }
+
+ // Check for errors
+ if( bytes < 0 ) {
+ fprintf(stderr, "ERROR: Unable to recieve from client on socket %i\n", Socket);
+ return ;
+ }
+}