Merge pull request #108 from an-tao/dev

Fix a websocket bug in Linux and add ws_test.html for testing
This commit is contained in:
An Tao 2019-04-05 11:58:08 +08:00 committed by GitHub
commit 524ad6ce22
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<!DOCTYPE html>
<pre id="log"></pre>
<script>
// helper function: log message to screen
function log(msg) {
document.getElementById('log').textContent += msg + '\n';
}
// setup websocket with callbacks
var ws = new WebSocket("ws://127.0.0.1:8848/chat");
ws.onopen = function() {
log('CONNECT');
ws.send("hello!!!");
};
ws.onclose = function() {
log('DISCONNECT');
};
ws.onmessage = function(event) {
log('MESSAGE: ' + event.data);
ws.send(event.data);
ws.send(event.data);
};
</script>

View File

@ -318,6 +318,9 @@ void HttpAppFrameworkImpl::run()
#endif #endif
} }
serverPtr->setHttpAsyncCallback(std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2)); serverPtr->setHttpAsyncCallback(std::bind(&HttpAppFrameworkImpl::onAsyncRequest, this, _1, _2));
serverPtr->setNewWebsocketCallback(std::bind(&HttpAppFrameworkImpl::onNewWebsockRequest, this, _1, _2, _3));
serverPtr->setWebsocketMessageCallback(std::bind(&HttpAppFrameworkImpl::onWebsockMessage, this, _1, _2));
serverPtr->setDisconnectWebsocketCallback(std::bind(&HttpAppFrameworkImpl::onWebsockDisconnect, this, _1));
serverPtr->setConnectionCallback(std::bind(&HttpAppFrameworkImpl::onConnection, this, _1)); serverPtr->setConnectionCallback(std::bind(&HttpAppFrameworkImpl::onConnection, this, _1));
serverPtr->kickoffIdleConnections(_idleConnectionTimeout); serverPtr->kickoffIdleConnections(_idleConnectionTimeout);
serverPtr->start(); serverPtr->start();