I have my server sending a large file to client(web browser) but when i refresh my page i am getting the conection reset by peer error and the program terminates. What i am expecting is server get a new connectiont.
while (true)
{
check((new_socket = accept(server_fd, (struct sockaddr *)&address,
(socklen_t *)&addrlen)),
"accept_failed");
read(new_socket, buffer_recv, 1024);
printf("%s\n", buffer_recv);
T = std::thread(handle_connection, new_socket);
T.detach();
}
handle_connection contains
while (file.read(&buffer[0], 1024))
{
s = file.gcount();
content = chunk::make_chunk(buffer, s);
check(write(new_socket, &content[0], content.size()), "Write_error");
}
where check being simple error handling function and make_chunk return string.How can i make the server from not exiting and continue listening for connection please answer i am new to socket programming