add a simple httpd server standalone example
This commit is contained in:
parent
4872b59fac
commit
b0b451d2c7
45
httpd.cpp
Normal file
45
httpd.cpp
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* httpd.cpp
|
||||||
|
* Author: Benjamin Sergeant
|
||||||
|
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved.
|
||||||
|
*
|
||||||
|
* Buid with make httpd
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ixwebsocket/IXHttpServer.h>
|
||||||
|
#include <sstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
if (argc != 3)
|
||||||
|
{
|
||||||
|
std::cerr << "Usage: httpd <port> <host>" << std::endl;
|
||||||
|
std::cerr << " ./a.out 9090 127.0.0.1" << std::endl;
|
||||||
|
std::cerr << " ./a.out 9090 0.0.0.0" << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
int port;
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << argv[1];
|
||||||
|
ss >> port;
|
||||||
|
std::string hostname(argv[2]);
|
||||||
|
|
||||||
|
std::cout << "Listening on " << hostname
|
||||||
|
<< ":" << port << std::endl;
|
||||||
|
|
||||||
|
ix::HttpServer server(port, hostname);
|
||||||
|
|
||||||
|
auto res = server.listen();
|
||||||
|
if (!res.first)
|
||||||
|
{
|
||||||
|
std::cout << res.second << std::endl;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
server.start();
|
||||||
|
server.wait();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
22
makefile
22
makefile
@ -169,6 +169,28 @@ ws_test: ws
|
|||||||
autobahn_report:
|
autobahn_report:
|
||||||
cp -rvf ~/sandbox/reports/clients/* ../bsergean.github.io/IXWebSocket/autobahn/
|
cp -rvf ~/sandbox/reports/clients/* ../bsergean.github.io/IXWebSocket/autobahn/
|
||||||
|
|
||||||
|
httpd:
|
||||||
|
clang++ --std=c++14 --stdlib=libc++ httpd.cpp \
|
||||||
|
ixwebsocket/IXSelectInterruptFactory.cpp \
|
||||||
|
ixwebsocket/IXCancellationRequest.cpp \
|
||||||
|
ixwebsocket/IXSocketTLSOptions.cpp \
|
||||||
|
ixwebsocket/IXUserAgent.cpp \
|
||||||
|
ixwebsocket/IXDNSLookup.cpp \
|
||||||
|
ixwebsocket/IXBench.cpp \
|
||||||
|
ixwebsocket/IXWebSocketHttpHeaders.cpp \
|
||||||
|
ixwebsocket/IXSelectInterruptPipe.cpp \
|
||||||
|
ixwebsocket/IXHttp.cpp \
|
||||||
|
ixwebsocket/IXSocketConnect.cpp \
|
||||||
|
ixwebsocket/IXSocket.cpp \
|
||||||
|
ixwebsocket/IXSocketServer.cpp \
|
||||||
|
ixwebsocket/IXNetSystem.cpp \
|
||||||
|
ixwebsocket/IXHttpServer.cpp \
|
||||||
|
ixwebsocket/IXSocketFactory.cpp \
|
||||||
|
ixwebsocket/IXConnectionState.cpp \
|
||||||
|
ixwebsocket/IXUrlParser.cpp \
|
||||||
|
ixwebsocket/IXSelectInterrupt.cpp \
|
||||||
|
ixwebsocket/apple/IXSetThreadName_apple.cpp -lz
|
||||||
|
|
||||||
# For the fork that is configured with appveyor
|
# For the fork that is configured with appveyor
|
||||||
rebase_upstream:
|
rebase_upstream:
|
||||||
git fetch upstream
|
git fetch upstream
|
||||||
|
Loading…
Reference in New Issue
Block a user