-
Notifications
You must be signed in to change notification settings - Fork 0
/
glovewsecho.cc
78 lines (67 loc) · 2.11 KB
/
glovewsecho.cc
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
*************************************************************
* @file webserver.cpp
* @brief Breve descripción
* Pequeña documentación del archivo
*
*
*
*
*
* @author Gaspar Fernández <blakeyed@totaki.com>
* @version
* @date 03 abr 2015
* Changelog:
*
*
*
*
* Compilation:
* $ g++ -g -o webserver webserver.cpp glovehttpserver.cpp glove.o -std=c++11 -lpthread -lcrypto -lssl
*
*************************************************************/
#include "glovehttpserver.hpp"
#include <iostream>
#include <chrono>
#include <thread>
#include <zlib.h>
void other(GloveHttpRequest &request, GloveHttpResponse& response)
{
response << "This is an echo server for web sockets\n";
auto uri = request.getUri().servicehost("ws");
response << "Try connecting to " << uri <<"/echo/ \n";
}
/* void echoEngine(GloveHttpRequest &request, GloveWebSocketHandler& ws) */
/* { */
/* } */
void echoEngine(GloveHttpRequest &request, GloveHttpResponse& response)
{
response << "This is an Echo engine for Web Sockets.\n";
auto uri = request.getUri().servicehost("ws");
response << "Try connecting to " << uri <<"/echo/ \n";
}
void echoMessage(GloveWebSocketData& data, GloveWebSocketHandler& ws)
{
if (data.length()>300)
ws.send("Message too long");
else
ws.send("Echo: "+data.data());
}
bool chatmaintenance(GloveWebSocketHandler& ws)
{
}
int main(int argc, char *argv[])
{
GloveHttpServer serv(8080, "", 2048);
std::cout << "Timeout: "<<serv.timeout()<<std::endl;
std::cout << "Keepalive: "<<serv.keepalive_timeout()<<std::endl;
serv.addWebSocket("/echo/", echoEngine, nullptr, echoMessage);
serv.addRoute("/websocket_test.js", std::bind(GloveHttpServer::fileServerFixed, std::placeholders::_1, std::placeholders::_2, "websocket_test.js"));
serv.addRoute("/websocket_test.css", std::bind(GloveHttpServer::fileServerFixed, std::placeholders::_1, std::placeholders::_2, "websocket_test.css"));
serv.addRoute("/", std::bind(GloveHttpServer::fileServerFixed, std::placeholders::_1, std::placeholders::_2, "websockets.html"));
std::cout << "READY"<<std::endl;
while(1)
{
std::this_thread::sleep_for(std::chrono::seconds(1));
}
}