| 1 |
/* |
| 2 |
* httpd.cpp |
| 3 |
* Author: Benjamin Sergeant |
| 4 |
* Copyright (c) 2020 Machine Zone, Inc. All rights reserved. |
| 5 |
* |
| 6 |
* Buid with make httpd |
| 7 |
*/ |
| 8 |
|
| 9 |
#include <ixwebsocket/IXHttpServer.h> |
| 10 |
#include <sstream> |
| 11 |
#include <iostream> |
| 12 |
|
| 13 |
int main(int argc, char** argv) |
| 14 |
{ |
| 15 |
if (argc != 3) |
| 16 |
{ |
| 17 |
std::cerr << "Usage: " << argv[0] |
| 18 |
<< " <port> <host>" << std::endl; |
| 19 |
std::cerr << " " << argv[0] << " 9090 127.0.0.1" << std::endl; |
| 20 |
std::cerr << " " << argv[0] << " 9090 0.0.0.0" << std::endl; |
| 21 |
return 1; |
| 22 |
} |
| 23 |
|
| 24 |
int port; |
| 25 |
std::stringstream ss; |
| 26 |
ss << argv[1]; |
| 27 |
ss >> port; |
| 28 |
std::string hostname(argv[2]); |
| 29 |
|
| 30 |
std::cout << "Listening on " << hostname |
| 31 |
<< ":" << port << std::endl; |
| 32 |
|
| 33 |
ix::HttpServer server(port, hostname); |
| 34 |
|
| 35 |
auto res = server.listen(); |
| 36 |
if (!res.first) |
| 37 |
{ |
| 38 |
std::cout << res.second << std::endl; |
| 39 |
return 1; |
| 40 |
} |
| 41 |
|
| 42 |
server.start(); |
| 43 |
server.wait(); |
| 44 |
|
| 45 |
return 0; |
| 46 |
} |