Пример #1
0
bool HttpServer::initWebSocket(HttpServerConnection& connection, HttpRequest& request, HttpResponse& response)
{
	if (!wsEnabled)
		return false;

    WebSocket *sock = new WebSocket(&connection);
    if (!sock->initialize(request, response))
        return false;

    connection.setTimeOut(USHRT_MAX); //Disable disconnection on connection idle (no rx/tx)
	connection.setDisconnectionHandler(HttpServerConnectionDelegate(&HttpServer::onCloseWebSocket, this)); // auto remove on close
	response.sendHeader(connection); // Will push header before user data

    wsocks.addElement(sock);
    if (wsConnect) wsConnect(*sock);
    if (wsCommandEnabled &&  (request.getQueryParameter(wsCommandRequestParam) == "true"))
    {
#if ENABLE_CMD_EXECUTOR
        debugf("WebSocket Commandprocessor started");
#else
        debugf("WebSocket Commandprocessor support DISABLED via ENABLE_CMD_EXECUTOR");
#endif
    	sock->enableCommand();
    }
}
Пример #2
0
bool HttpServer::initWebSocket(HttpServerConnection& connection, HttpRequest& request, HttpResponse& response)
{
	if (!wsEnabled)
		return false;

	auto sock = WebSocket(&connection);
	if (!sock.initialize(request, response))
		return false;

	connection.setDisconnectionHandler(HttpServerConnectionDelegate(&HttpServer::onCloseWebSocket, this)); // auto remove on close
	response.sendHeader(connection); // Will push header before user data

	wsocks.add(sock);
	if (wsConnect) wsConnect(sock);

	return true;
}