I used ws to implement my websocket server and in the api docs i found it has a ping/pong event,however, i couldn't received the event.
server:
wss.on("connection", function connection(ws) {
ws.on('message', function(message) {
console.log('received: %s', message);
});
ws.onclose = function () {
console.log('client disappeared');
};
ws.ping('hello');//Send a ping
});
client:
<script>
var ws = new WebSocket('ws://localhost:8080');
function sendMesage() {
ws.send('hello');
}
ws.onopen = function () {
console.log('connection to server opened');
};
ws.onclose = function () {
console.log('closed');
}
ws.onping = function () {
console.log('ping');
};// expect to receive ping event
</script>
via user7238980
No comments:
Post a Comment