-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
57 lines (46 loc) · 1.15 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <Poco/Net/ServerSocket.h>
#include <Poco/Net/SocketAddress.h>
#include <Poco/Net/StreamSocket.h>
#include <Poco/Net/SocketStream.h>
#include <pthread.h>
#include <unistd.h>
#include <stdio.h>
#include <fstream>
#include <iostream>
using namespace Poco::Net;
#define PORT 1600
#define IPADDR "192.168.10.100"
#define UPDATE_HTMLDOC_TIMEOUT 5
char buff[4096];
void updateHtmlDoc()
{
std::fstream html;
html.open("index.html");
html.read(buff, sizeof(buff));
html.close();
}
void* retakeHtmlDoc(void* thread_data)
{
while (true)
{
updateHtmlDoc();
sleep(UPDATE_HTMLDOC_TIMEOUT);
}
}
int main(int argc, char const *argv[])
{
SocketAddress serverAddr(IPADDR, PORT);
ServerSocket server(serverAddr);
pthread_t thread;
pthread_create(&thread, NULL, retakeHtmlDoc, NULL);
while (true)
{
SocketStream connectedSocket(server.acceptConnection());
connectedSocket << "HTTP/1.0 200 OK\r\n"
<< "Content-Type: text/html\r\n"
<< "\r\n"
<< buff << std::flush;
connectedSocket.close();
}
return 0;
}