mirror of
https://github.com/davisking/dlib.git
synced 2024-11-01 10:14:53 +08:00
Updated examples to use the simpler start_async() to start the servers.
This commit is contained in:
parent
6503f87480
commit
2c1332b382
@ -13,7 +13,6 @@
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include "dlib/server.h"
|
||||
#include "dlib/ref.h" // for ref()
|
||||
|
||||
using namespace dlib;
|
||||
using namespace std;
|
||||
@ -92,24 +91,6 @@ class web_server : public server::http_1a_c
|
||||
|
||||
};
|
||||
|
||||
void thread(web_server& the_server)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Start the server. start() blocks until the server is shutdown
|
||||
// by a call to clear()
|
||||
the_server.start();
|
||||
}
|
||||
catch (socket_error& e)
|
||||
{
|
||||
cout << "Socket error while starting server: " << e.what() << endl;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cout << "Error while starting server: " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
@ -119,15 +100,11 @@ int main()
|
||||
|
||||
// make it listen on port 5000
|
||||
our_web_server.set_listening_port(5000);
|
||||
|
||||
// create a thread that will start the server. The ref() here allows us to pass
|
||||
// our_web_server into the threaded function by reference.
|
||||
thread_function t(thread, dlib::ref(our_web_server));
|
||||
// Tell the server to begin accepting connections.
|
||||
our_web_server.start_async();
|
||||
|
||||
cout << "Press enter to end this program" << endl;
|
||||
cin.get();
|
||||
// this will cause the server to shut down
|
||||
our_web_server.clear();
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
|
@ -14,7 +14,6 @@
|
||||
|
||||
#include "dlib/sockets.h"
|
||||
#include "dlib/server.h"
|
||||
#include "dlib/ref.h" // for ref()
|
||||
#include <iostream>
|
||||
|
||||
using namespace dlib;
|
||||
@ -43,25 +42,6 @@ class serv : public server::kernel_1a_c
|
||||
};
|
||||
|
||||
|
||||
void thread(serv& our_server)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Start the server. start() blocks until the server is shutdown
|
||||
// by a call to clear()
|
||||
our_server.start();
|
||||
}
|
||||
catch (socket_error& e)
|
||||
{
|
||||
cout << "Socket error while starting server: " << e.what() << endl;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cout << "Error while starting server: " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
@ -71,15 +51,11 @@ int main()
|
||||
// set up the server object we have made
|
||||
our_server.set_listening_port(1234);
|
||||
our_server.set_max_connections(1000);
|
||||
|
||||
// create a thread that will start the server. The ref() here allows us to pass
|
||||
// our_server into the threaded function by reference.
|
||||
thread_function t(thread, dlib::ref(our_server));
|
||||
// Tell the server to begin accepting connections.
|
||||
our_server.start_async();
|
||||
|
||||
cout << "Press enter to end this program" << endl;
|
||||
cin.get();
|
||||
// this will cause the server to shut down
|
||||
our_server.clear();
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
|
@ -25,7 +25,6 @@
|
||||
#include "dlib/sockets.h"
|
||||
#include "dlib/server.h"
|
||||
#include "dlib/sockstreambuf.h"
|
||||
#include "dlib/ref.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace dlib;
|
||||
@ -70,25 +69,6 @@ class serv : public server::kernel_1a_c
|
||||
};
|
||||
|
||||
|
||||
void thread(serv& our_server)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Start the server. start() blocks until the server is shutdown
|
||||
// by a call to clear()
|
||||
our_server.start();
|
||||
}
|
||||
catch (socket_error& e)
|
||||
{
|
||||
cout << "Socket error while starting server: " << e.what() << endl;
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
cout << "Error while starting server: " << e.what() << endl;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
try
|
||||
@ -98,15 +78,11 @@ int main()
|
||||
// set up the server object we have made
|
||||
our_server.set_listening_port(1234);
|
||||
our_server.set_max_connections(1000);
|
||||
|
||||
// create a thread that will start the server. The ref() here allows us to pass
|
||||
// our_server into the threaded function by reference.
|
||||
thread_function t(thread, dlib::ref(our_server));
|
||||
// Tell the server to begin accepting connections.
|
||||
our_server.start_async();
|
||||
|
||||
cout << "Press enter to end this program" << endl;
|
||||
cin.get();
|
||||
// this will cause the server to shut down
|
||||
our_server.clear();
|
||||
}
|
||||
catch (exception& e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user