Skip to content

Commit

Permalink
demo OK
Browse files Browse the repository at this point in the history
  • Loading branch information
fookwood committed Aug 28, 2012
1 parent 2ca0ef6 commit 9e4e33b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
19 changes: 17 additions & 2 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@

int server_port = 80; // 0 stands any port can be ok.
char server_root[100] = "/var/www";
int setsockoptflag = -1;
int setsockoptflag = 1;
int server_sock;

char buf[10000];
char temp[] = "HTTP/1.1 200 OK\r\nContent-Type:text/html\r\n\r\nThis page you see";
int main(void){

int connfd,n;
server_sock = server_start();

printf("Server start running at port 80 :)\n");
while( 1 ){

connfd = accept( server_sock, NULL, NULL );
n=read(connfd,buf,10000);
buf[n] = 0;
puts(buf);

write( connfd, temp, sizeof(temp) );

close(connfd);
}

return 0;
}

2 changes: 2 additions & 0 deletions utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ int server_start( void ){
if( fd == -1 )
err_exit("Can't get socket");

setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &setsockoptflag, setsockoptflag );

servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(server_port);
servaddr.sin_addr.s_addr = htonl( INADDR_ANY );
Expand Down

0 comments on commit 9e4e33b

Please sign in to comment.