mirror of
https://github.com/rwengine/openrw.git
synced 2024-11-22 10:22:52 +01:00
Accept incoming connections in a loop
This commit is contained in:
parent
fc0777717e
commit
dc9c4c3b72
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user