This repository has been archived by the owner on Mar 30, 2022. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Send close frames on close() or on receipt of a close frame from the server. - Add a timeout option to close() to handle servers that don't properly support client-initiated close handshaking. - Re-jigger unit tests to avoid client-initiated closes, as the WS server that we're using doesn't support this.
- Loading branch information
Showing
5 changed files
with
131 additions
and
54 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Verify that a connection can be closed gracefully from both directions. | ||
|
||
var assert = require('assert'); | ||
var WebSocket = require('../lib/websocket').WebSocket; | ||
var WebSocketServer = require('websocket-server/ws/server').Server; | ||
|
||
var PORT = 1024 + Math.floor(Math.random() * 4096); | ||
|
||
var clientGotServerClose = false; | ||
var serverGotClientClose = false; | ||
|
||
var wss = new WebSocketServer(); | ||
wss.listen(PORT, 'localhost'); | ||
wss.on('connection', function(c) { | ||
c.on('close', function() { | ||
serverGotClientClose = true; | ||
wss.close(); | ||
}); | ||
|
||
c.close(); | ||
}); | ||
|
||
var ws = new WebSocket('ws://localhost:' + PORT); | ||
ws.onclose = function() { | ||
assert.equal(ws.CLOSED, ws.readyState); | ||
clientGotServerClose = true; | ||
}; | ||
|
||
process.on('exit', function() { | ||
assert.ok(clientGotServerClose); | ||
assert.ok(serverGotClientClose); | ||
}); |
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
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