Skip to content

Commit 9e4e33b

Browse files
committed
demo OK
1 parent 2ca0ef6 commit 9e4e33b

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

main.c

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,28 @@
22

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

8+
char buf[10000];
9+
char temp[] = "HTTP/1.1 200 OK\r\nContent-Type:text/html\r\n\r\nThis page you see";
810
int main(void){
9-
11+
int connfd,n;
1012
server_sock = server_start();
1113

14+
printf("Server start running at port 80 :)\n");
15+
while( 1 ){
16+
17+
connfd = accept( server_sock, NULL, NULL );
18+
n=read(connfd,buf,10000);
19+
buf[n] = 0;
20+
puts(buf);
21+
22+
write( connfd, temp, sizeof(temp) );
23+
24+
close(connfd);
25+
}
26+
1227
return 0;
1328
}
1429

utils.c

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ int server_start( void ){
1414
if( fd == -1 )
1515
err_exit("Can't get socket");
1616

17+
setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &setsockoptflag, setsockoptflag );
18+
1719
servaddr.sin_family = AF_INET;
1820
servaddr.sin_port = htons(server_port);
1921
servaddr.sin_addr.s_addr = htonl( INADDR_ANY );

0 commit comments

Comments
 (0)