Some problems:
1) You do not have enough comma to panic ("listen")
2) You declare "sd" twice (one on main () one on the other)
#include <stdio.h> #include <pthread.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <netinet/ip.h> #define SERVER_PORT 30000 int main(int argv, char *args[]) { struct sockaddr_in addr; int sd, port; port = htons(SERVER_PORT); /*--- create socket ---*/ sd = socket(PF_INET, SOCK_STREAM, 0); /*--- bind port/address to socket ---*/ memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; addr.sin_port = port; addr.sin_addr.s_addr = INADDR_ANY; /* any interface */ bind(sd, (struct sockaddr*)&addr, sizeof(addr)); /*--- make into listener with 10 slots ---*/ listen(sd, 10); /*--- begin waiting for connections ---*/ pthread_t child; FILE *fp; while (1) /* process all incoming clients */ { printf("before accept\n"); sd = accept(sd, 0, 0); /* accept connection */ fp = fdopen(sd, "wr+"); /* convert into FILE* */ //pthread_create(&child, 0, servlet, fp); /* start thread */ //pthread_detach(child); /* don't track it */ printf("After accept\n"); } }
beder source share