You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

46 lines
940 B

//
// server.cpp
// TP C++
// Eric Lecolinet - Telecom ParisTech - 2016.
//
#include <memory>
#include <string>
#include <iostream>
#include <sstream>
#include "tcpserver.h"
const int PORT = 3331;
int main(int argc, char* argv[])
{
// cree le TCPServer
auto* server =
new TCPServer( [&](std::string const& request, std::string& response) {
// the request sent by the client to the server
std::cout << "request: " << request << std::endl;
// the response that the server sends back to the client
response = "RECEIVED: " + request;
// return false would close the connecytion with the client
return true;
});
// lance la boucle infinie du serveur
std::cout << "Starting Server on port " << PORT << std::endl;
int status = server->run(PORT);
// en cas d'erreur
if (status < 0) {
std::cerr << "Could not start Server on port " << PORT << std::endl;
return 1;
}
return 0;
}