Difference between revisions of "Server.c"
From Organic Design wiki
(place code in one segment at a time) |
m |
||
| Line 3: | Line 3: | ||
// SRC: http://www.organicdesign.co.nz/server.c | // SRC: http://www.organicdesign.co.nz/server.c | ||
| − | |||
#define DELAY 1 // normal operation is 0 for no delay | #define DELAY 1 // normal operation is 0 for no delay | ||
#define PAKSIZE 128 // keep packet-size small for non-multithreaded design | #define PAKSIZE 128 // keep packet-size small for non-multithreaded design | ||
| Line 18: | Line 17: | ||
#include <fcntl.h> // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL | #include <fcntl.h> // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL | ||
#endif | #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 = htons(atoi(*hash("port"))); // get port from arg-hash | ||
| + | addr->sin_addr.s_addr = htonl(INADDR_ANY); | ||
Revision as of 12:45, 21 July 2006
// 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
- define DELAY 1 // normal operation is 0 for no delay
- define PAKSIZE 128 // keep packet-size small for non-multithreaded design
- define BUFSIZE 10000 // dictates max message size
- define MAXCLIENTS 1000 // used by listen()
- ifdef WINDOWS
- include <winsock.h>
- else
- include <sys/socket.h>
- include <sys/select.h>
- include <netinet/in.h>
- include <sys/time.h> // for select()
- include <fcntl.h> // O_RDWR, O_NONBLOCK, F_GETFL, F_SETFL
- 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 = htons(atoi(*hash("port"))); // get port from arg-hash addr->sin_addr.s_addr = htonl(INADDR_ANY);



