Last active
November 17, 2017 08:43
-
-
Save grimmerk/3adae3f9b6151b9e940cfc0042164afe to your computer and use it in GitHub Desktop.
qtwebsocket
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// not use now | |
// uWebSockets part, comment now, change to use qt's built-in WebSocket | |
//TODO Grimmer: this is for new CARTA, and is using hacked way to workaround passing command/object id/callback issue. | |
// void SessionDispatcher::startWebSocketServer() { | |
// std::cout << "websocket starts running" << std::endl; | |
// uWS::Hub h; | |
// // DesktopConnector *conn = this; | |
// h.onMessage([this](uWS::WebSocket<uWS::SERVER> *ws, char *message, size_t length, uWS::OpCode opCode) { | |
// std::cout << "get something, echo back:" << message << std::endl; | |
// // ws->send(message, length, opCode); | |
// char *psz = new char[length]; | |
// strncpy(psz, message, length); | |
// QString message2(psz); | |
// delete [] psz; | |
// qDebug() << "convert to:"<< message2; | |
// if (message2.contains("REQUEST_FILE_LIST")) { | |
// // if ( ) | |
// QString command = "/CartaObjects/DataLoader:getData"; | |
// QString parameter = "path:"; | |
//// QMetaObject::invokeMethod( this, "jsSendCommandSlot2", Qt::QueuedConnection ); | |
// // conn->jsSendCommandSlot(command, parameter); | |
// // QMetaObject::invokeMethod(this, "quit", | |
// // Qt::QueuedConnection); | |
//// pseudoJsSendCommandSlot(ws, opCode, command, parameter); | |
// // SessionDispatcher::jsSendCommandSlot(const QString &cmd, const QString & parameter) | |
// // /CartaObjects/DataLoader:getData | |
// // path: | |
// } else if (message2.contains("SELECT_FILE_TO_OPEN")) { | |
// QStringList myStringList = message2.split(';'); | |
// if(myStringList.size()>=2){ | |
// auto fileName = myStringList[1]; | |
// qDebug()<< "fileName:" << myStringList[1]; | |
// QString command = "/CartaObjects/ViewManager:dataLoaded"; | |
// QString parameter = "id:/CartaObjects/c14,data:" + fileName; | |
//// pseudoJsSendCommandSlot(ws, opCode, command, parameter); | |
//// qDebug()<<"cmd:"<<cmd; | |
//// qDebug()<<"parameter:"<< parameter; | |
//// if (cmd=="/CartaObjects/ViewManager:dataLoaded") { | |
//// if (parameter=="id:/CartaObjects/c14,data:/Users/grimmer/CARTA/Images/aJ.fits") { | |
//// int kkk =0; | |
//// } | |
//// } | |
// } | |
// // ws->send("hello", 5, opCode); | |
// } else { | |
//// ws->send("hello", 5, opCode); | |
// } | |
// }); | |
// h.listen(4314); | |
// h.run(); // will block here | |
// std::cout << "websocket ends running" << std::endl; | |
// } | |
//void SessionDispatcher::receiveNewSession(int SessionID){ | |
//} | |
//SessionDispatcher::SessionDispatcher() | |
//{ | |
// queued connection to prevent callbacks from firing inside setState | |
// connect( this, & SessionDispatcher::stateChangedSignal, | |
// this, & SessionDispatcher::stateChangedSlot, | |
// Qt::QueuedConnection ); | |
// | |
// m_callbackNextId = 0; | |
// test1: uWebSocket part | |
// std::thread mThread( &SessionDispatcher::startWebSocketServer, this ); | |
// mThread.detach(); | |
// test2: change to use Qt's buint-in WebSocket | |
// https://github.com/GarageGames/Qt/blob/master/qt-5/qtwebsockets/examples/websockets/echoserver/echoserver.cpp | |
// m_pWebSocketServer = new QWebSocketServer(QStringLiteral("Echo Server"), | |
// QWebSocketServer::NonSecureMode, this); | |
// m_debug = true; | |
// int port = 4317; | |
// if (m_pWebSocketServer->listen(QHostAddress::Any, port)) { | |
// if (m_debug) | |
// qDebug() << "DesktopConnector listening on port" << port; | |
// connect(m_pWebSocketServer, &QWebSocketServer::newConnection, | |
// this, &SessionDispatcher::onNewConnection); | |
// // connect(m_pWebSocketServer, &QWebSocketServer::closed, this, &SessionDispatcher::closed); | |
// } | |
//} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment