-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bind service to specific IP address.
- Loading branch information
1 parent
5caa529
commit 41b77e1
Showing
12 changed files
with
108 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Example illustrating binding service to specific address. | ||
* | ||
* Server Usage: | ||
* ./distribution/example/bind_service_address | ||
* | ||
* Client Usage: | ||
* curl -w'\n' -v -XGET 'http://127.0.0.1:1984/resource' | ||
*/ | ||
|
||
#include <memory> | ||
#include <cstdlib> | ||
#include <restbed> | ||
|
||
using namespace std; | ||
using namespace restbed; | ||
|
||
void get_method_handler( const shared_ptr< Session >& session ) | ||
{ | ||
session->close( OK, "Hello, World!", { { "Content-Length", "13" } } ); | ||
} | ||
|
||
int main( const int, const char** ) | ||
{ | ||
auto resource = make_shared< Resource >( ); | ||
resource->set_path( "/resource" ); | ||
resource->set_method_handler( "GET", get_method_handler ); | ||
|
||
auto settings = make_shared< Settings >( ); | ||
settings->set_port( 1984 ); | ||
settings->set_bind_address( "127.0.0.1" ); | ||
settings->set_default_header( "Connection", "close" ); | ||
|
||
Service service; | ||
service.publish( resource ); | ||
service.start( settings ); | ||
|
||
return EXIT_SUCCESS; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters