src/​examples/​cpp03/​http/​server/​main.​cppsrc/​examples/​cpp11/​http/​server/​main.​cpp
⋮⋮
1 /​/​1 /​/​
2 /​/​·​main.​cpp2 /​/​·​main.​cpp
3 /​/​·​~~~~~~~~3 /​/​·​~~~~~~~~
4 /​/​4 /​/​
5 /​/​·​Copyright·​(c)​·​2003-​2022·​Christopher·​M.​·​Kohlhoff·​(chris·​at·​kohlhoff·​dot·​com)​5 /​/​·​Copyright·​(c)​·​2003-​2022·​Christopher·​M.​·​Kohlhoff·​(chris·​at·​kohlhoff·​dot·​com)​
6 /​/​6 /​/​
7 /​/​·​Distributed·​under·​the·​Boost·​Software·​License,​·​Version·​1.​0.​·​(See·​accompanying7 /​/​·​Distributed·​under·​the·​Boost·​Software·​License,​·​Version·​1.​0.​·​(See·​accompanying
8 /​/​·​file·​LICENSE_1_0.​txt·​or·​copy·​at·​http:​/​/​www.​boost.​org/​LICENSE_1_0.​txt)​8 /​/​·​file·​LICENSE_1_0.​txt·​or·​copy·​at·​http:​/​/​www.​boost.​org/​LICENSE_1_0.​txt)​
9 /​/​9 /​/​
10 10
11 #include·​<iostream>11 #include·​<iostream>
12 #include·​<string>12 #include·​<string>
13 #include·​<asio.​hpp>13 #include·​<asio.​hpp>
14 #include·​<boost/​bind/​bind.​hpp>
15 #include·​"server.​hpp"14 #include·​"server.​hpp"
16 15
17 int·​main(int·​argc,​·​char*·​argv[])​16 int·​main(int·​argc,​·​char*·​argv[])​
18 {17 {
19 ·​·​try18 ·​·​try
20 ·​·​{19 ·​·​{
21 ·​·​·​·​/​/​·​Check·​command·​line·​arguments.​20 ·​·​·​·​/​/​·​Check·​command·​line·​arguments.​
22 ·​·​·​·​if·​(argc·​!=·​4)​21 ·​·​·​·​if·​(argc·​!=·​4)​
23 ·​·​·​·​{22 ·​·​·​·​{
24 ·​·​·​·​·​·​std:​:​cerr·​<<·​"Usage:​·​http_server·​<address>·​<port>·​<doc_root>\n";​23 ·​·​·​·​·​·​std:​:​cerr·​<<·​"Usage:​·​http_server·​<address>·​<port>·​<doc_root>\n";​
25 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​For·​IPv4,​·​try:​\n";​24 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​For·​IPv4,​·​try:​\n";​
26 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​·​·​receiver·​0.​0.​0.​0·​80·​.​\n";​25 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​·​·​receiver·​0.​0.​0.​0·​80·​.​\n";​
27 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​For·​IPv6,​·​try:​\n";​26 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​For·​IPv6,​·​try:​\n";​
28 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​·​·​receiver·​0:​:​0·​80·​.​\n";​27 ·​·​·​·​·​·​std:​:​cerr·​<<·​"·​·​·​·​receiver·​0:​:​0·​80·​.​\n";​
29 ·​·​·​·​·​·​return·​1;​28 ·​·​·​·​·​·​return·​1;​
30 ·​·​·​·​}29 ·​·​·​·​}
31 30
32 ·​·​·​·​/​/​·​Initialise·​the·​server.​31 ·​·​·​·​/​/​·​Initialise·​the·​server.​
33 ·​·​·​·​http:​:​server:​:​server·​s(argv[1],​·​argv[2],​·​argv[3])​;​32 ·​·​·​·​http:​:​server:​:​server·​s(argv[1],​·​argv[2],​·​argv[3])​;​
34 33
35 ·​·​·​·​/​/​·​Run·​the·​server·​until·​stopped.​34 ·​·​·​·​/​/​·​Run·​the·​server·​until·​stopped.​
36 ·​·​·​·​s.​run()​;​35 ·​·​·​·​s.​run()​;​
37 ·​·​}36 ·​·​}
38 ·​·​catch·​(std:​:​exception&·​e)​37 ·​·​catch·​(std:​:​exception&·​e)​
39 ·​·​{38 ·​·​{
40 ·​·​·​·​std:​:​cerr·​<<·​"exception:​·​"·​<<·​e.​what()​·​<<·​"\n";​39 ·​·​·​·​std:​:​cerr·​<<·​"exception:​·​"·​<<·​e.​what()​·​<<·​"\n";​
41 ·​·​}40 ·​·​}
42 41
43 ·​·​return·​0;​42 ·​·​return·​0;​
44 }43 }