1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-09-18 16:32:32 +02:00

Accept incoming connections in a loop

This commit is contained in:
Timmy Sjöstedt 2015-04-25 01:08:19 +02:00
parent fc0777717e
commit dc9c4c3b72

View File

@ -15,22 +15,24 @@ void HttpServer::run()
std::cout << "STARTING HTTP SERVER" << std::endl;
sf::TcpSocket client;
if (listener.accept(client) == sf::Socket::Done) {
std::cout << "New connection from "
<< client.getRemoteAddress() << ":" << client.getRemotePort()
<< std::endl;
while (true) {
sf::TcpSocket client;
if (listener.accept(client) == sf::Socket::Done) {
std::cout << "New connection from "
<< client.getRemoteAddress() << ":" << client.getRemotePort()
<< std::endl;
char buf[1024];
size_t received;
client.receive(buf, 1023, received);
buf[received] = '\0';
std::cout << "Got " << received << " bytes: " << buf << std::endl;
char buf[1024];
size_t received;
client.receive(buf, 1023, received);
buf[received] = '\0';
std::cout << "Got " << received << " bytes: " << buf << std::endl;
std::string response = dispatch();
client.send(response.c_str(), response.size());
std::string response = dispatch();
client.send(response.c_str(), response.size());
client.disconnect();
client.disconnect();
}
}
listener.close();