Server.c

From Organic Design wiki
Revision as of 12:47, 21 July 2006 by Nad (talk | contribs) (*hash?)

// This article and all its includes are licenced under LGPL // GPL: http://www.gnu.org/copyleft/lesser.html // SRC: http://www.organicdesign.co.nz/server.c

  1. define DELAY 1 // normal operation is 0 for no delay
  2. define PAKSIZE 128 // keep packet-size small for non-multithreaded design
  3. define BUFSIZE 10000 // dictates max message size
  4. define MAXCLIENTS 1000 // used by listen()
  1. ifdef WINDOWS
  2. include <winsock.h>
  3. else
  4. include <sys/socket.h>
  5. include <sys/select.h>
  6. include <netinet/in.h>
  7. include <sys/time.h> // for select()
  8. include <fcntl.h> // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL
  9. endif

// Set up structures for socket & select struct timeval to; fd_set *fdset; int sock, sockopt_on = 1, szAddr = sizeof(struct sockaddr_in); struct sockaddr_in *addr = calloc(1,szAddr); addr->sin_family = PF_INET; addr->sin_port = 2012; //htons(atoi(*hash("port"))); // get port from arg-hash addr->sin_addr.s_addr = htonl(INADDR_ANY);