1
0
mirror of https://github.com/lammertb/libhttp.git synced 2025-08-09 03:22:45 +03:00

Change dead links to Civetweb sourceforge page

This commit is contained in:
bel
2014-12-08 17:20:47 +01:00
parent d62e2c7a4e
commit 90fc294777
9 changed files with 161 additions and 9 deletions

View File

@@ -2,7 +2,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
<!-- This file is part of the Civetweb project,
http://code.google.com/p/civetweb -->
http://sourceforge.net/projects/civetweb/ -->
<head>
<title>Civetweb chat server</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
@@ -16,7 +16,7 @@
<div id="logo"></div>
<div class="rounded infobox help-message" id="motd">
Chat room implemented using
<a href="http://code.google.com/p/civetweb" target="_blank">Civetweb</a>
<a href="http://sourceforge.net/projects/civetweb/" target="_blank">Civetweb</a>
embeddable web server.
This application was written for educational purposes demonstrating
how web interface could be decoupled from the business logic. Not a

View File

@@ -2,7 +2,7 @@
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" dir="ltr">
<!-- This file is part of the Civetweb project,
http://code.google.com/p/civetweb -->
http://sourceforge.net/projects/civetweb/ -->
<head>
<title>Civetweb chat: login</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>

View File

@@ -1,4 +1,5 @@
// This file is part of Civetweb project, http://code.google.com/p/civetweb
// This file is part of Civetweb project,
// http://sourceforge.net/projects/civetweb/
var chat = {
// Backend URL, string.

View File

@@ -5,7 +5,7 @@ Content-Type: text/html
<p>This is another example of a Lua server page, served by
<a href="http://code.google.com/p/civetweb">Civetweb web server</a>.
<a href="http://sourceforge.net/projects/civetweb/">Civetweb web server</a>.
</p><p>
The following features are available:
<ul>

View File

@@ -3,7 +3,7 @@ mg.write("HTTP/1.0 200 OK\r\nContent-Type: text/html\r\n\r\n")
mg.write([[
<html><body>
<p>This is another example of a Lua script, creating a web page served by the
<a href="http://code.google.com/p/civetweb">Civetweb web server</a>.
<a href="http://sourceforge.net/projects/civetweb/">Civetweb web server</a>.
</p><p>
The following features are available:
<ul>

View File

@@ -4,7 +4,7 @@
<html><body>
<p>This is another example of a Lua server page, served by
<a href="http://code.google.com/p/civetweb">Civetweb web server</a>.
<a href="http://sourceforge.net/projects/civetweb/">Civetweb web server</a>.
</p><p>
The following features are available:
<ul>

View File

@@ -4,7 +4,7 @@ mg.write("\r\n")
mg.write([[<html><body>
<p>This is another example of a Lua server page, served by
<a href="http://code.google.com/p/civetweb">Civetweb web server</a>.
<a href="http://sourceforge.net/projects/civetweb/">Civetweb web server</a>.
</p><p>
The following features are available:
<ul>

View File

@@ -5,7 +5,7 @@ if canKeepAlive then
-- Create the entire response in a string variable first. Content-Length will be set to the length of this string.
reply = [[
<html><body>
<p>This is a Lua script supporting html keep-alive with the <a href="http://code.google.com/p/civetweb">Civetweb web server</a>.</p>
<p>This is a Lua script supporting html keep-alive with the <a href="http://sourceforge.net/projects/civetweb/">Civetweb web server</a>.</p>
<p>It works by setting the Content-Length header field properly.
</body></html>
]]

151
test/testclient.c Normal file
View File

@@ -0,0 +1,151 @@
#include <stdio.h>
#include <time.h>
#if defined(_WIN32) || defined(WIN32)
#include <Windows.h>
void INIT(void) {WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData);}
#else
#define INIT()
#include <unistd.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#endif
int connect_to_server(const struct sockaddr_in * serv_addr)
{
int sockfd;
/* Create a socket */
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd < 0) {
perror("ERROR opening socket");
return -1;
}
/* Connect to the server */
if (connect(sockfd, (const sockaddr *)serv_addr, sizeof(*serv_addr)) < 0) {
perror("ERROR connecting");
close(sockfd);
return -2;
}
return sockfd;
}
int send_to_server(int conn, const char * request)
{
int req_len = strlen(request);
int n;
n = write(conn, request, req_len);
if (n < 0) {
perror("ERROR writing to socket");
return 0;
}
return (n==req_len);
}
int read_from_server(int conn)
{
char rbuffer[1024];
int n;
long ret;
n = read(conn, rbuffer, sizeof(rbuffer));
if (n < 0) {
perror("ERROR reading from socket");
return 0;
}
if (strncmp("HTTP/1.", rbuffer, 7)) {
perror("ERROR not a HTTP response");
return 0;
}
ret = atol(rbuffer + 9);
return ret;
}
int main(int argc, char *argv[])
{
long portno;
int i, con_count=1;
time_t t1,t2,t3,t4;
char wbuffer[256];
int connlist[1024*65];
int result[1024*65];
struct hostent *server;
struct sockaddr_in serv_addr;
INIT();
if (argc != 4) {
fprintf(stderr,"Usage:\n\t%s hostname port clients\n\n", argv[0]);
exit(0);
}
con_count = atol(argv[3]);
if (con_count<1) con_count=1;
if (con_count>1024*65) con_count=1024*65;
portno = atol(argv[2]);
if (portno<1l || portno>0xFFFFl) {
fprintf(stderr, "ERROR, invalid port\n");
exit(0);
}
server = gethostbyname(argv[1]);
if (server == NULL) {
fprintf(stderr, "ERROR, no such host\n");
exit(0);
}
memset(&serv_addr, 0, sizeof(serv_addr));
serv_addr.sin_family = AF_INET;
memcpy(server->h_addr, &serv_addr.sin_addr.s_addr, server->h_length);
serv_addr.sin_port = htons((short)portno);
sprintf(wbuffer, "GET / HTTP/1.0\r\n\r\n");
t1 = time(0);
for (i=0;i<con_count;i++) {
result[i] = connlist[i] = connect_to_server(&serv_addr);
}
t2 = time(0);
for (i=0;i<con_count;i++) {
if (result[i]>=0) {
result[i] = send_to_server(connlist[i], wbuffer);
}
}
t3 = time(0);
for (i=0;i<con_count;i++) {
if (result[i]>=0) {
result[i] = read_from_server(connlist[i]);
}
}
t4 = time(0);
printf("\n");
printf("conn: %.0lf\n", difftime(t2,t1));
printf("write: %.0lf\n", difftime(t3,t2));
printf("read: %.0lf\n", difftime(t4,t3));
for (i=-10;i<1000;i++) {
int j,cnt=0;
for(j=0;j<con_count;j++) {
if (result[j]==i) cnt++;
}
if (cnt>0) {
printf("%5i\t%7u\n", i, cnt);
}
}
return 0;
}