3 * UCC (University [of WA] Computer Club) Electronic Accounting System
5 * server.c - Client Server Code
7 * This file is licenced under the 3-clause BSD Licence. See the file
8 * COPYING for full details.
13 #include <sys/socket.h>
15 #define MAX_CONNECTION_QUEUE 5
16 #define INPUT_BUFFER_SIZE 100
18 #define MSG_STR_TOO_LONG "499 Malformed Command String"
21 int giServer_Port = 1020;
24 void Server_Start(void)
29 void Server_HandleClient(int Socket)
31 char inbuf[INPUT_BUFFER_SIZE];
33 int remspace = INPUT_BUFFER_SIZE-1;
37 while( (bytes = recv(Socket, buf, remspace, 0)) > 0 )
40 buf[bytes] = '\0'; // Allow us to use stdlib string functions on it
44 while( (eol = strchr(start, '\n')) )
47 Server_ParseClientCommand(Socket, start);
51 // Check if there was an incomplete line
52 if( *start != '\0' ) {
53 int tailBytes = bytes - (start-buf);
54 // Roll back in buffer
55 memcpy(inbuf, start, tailBytes);
56 remspace -= tailBytes;
58 send(Socket, MSG_STR_TOO_LONG, sizeof(MSG_STR_TOO_LONG));
63 remspace = INPUT_BUFFER_SIZE - 1;
69 fprintf(stderr, "ERROR: Unable to recieve from client on socket %i\n", Socket);