зеркало из https://github.com/Azure/iisnode.git
websocket echo test
This commit is contained in:
Родитель
8184cc555f
Коммит
73d1082e5f
|
@ -58,6 +58,12 @@ if %ERRORLEVEL% neq 0 if %ERRORLEVEL% neq 183 (
|
|||
exit /b -1
|
||||
)
|
||||
|
||||
%appcmd% add app /site.name:%site% /path:/131_websocket_echo /physicalPath:"%www%\131_websocket_echo" /applicationPool:%apppool% >> %log%
|
||||
if %ERRORLEVEL% neq 0 if %ERRORLEVEL% neq 183 (
|
||||
echo FAILED. Cannot add app 131_websocket_echo to site %site%.
|
||||
exit /b -1
|
||||
)
|
||||
|
||||
set RETRY=0
|
||||
|
||||
:retry
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
A WebSocket connection receives 3 messages from the server
|
||||
*/
|
||||
|
||||
var WebSocket = require('faye-websocket')
|
||||
, iisnodeassert = require('iisnodeassert')
|
||||
, assert = require('assert');
|
||||
|
||||
var lines = ['The', 'cat', 'in', 'the', 'hat'];
|
||||
var address = iisnodeassert.getAddress('ws', '/131_websocket_echo/server.js');
|
||||
//var address = 'ws://localhost:8888/';
|
||||
var ws = new WebSocket.Client(address);
|
||||
var receiveIndex = 0;
|
||||
|
||||
var timeout = setTimeout(function () {
|
||||
assert.fail('10s', '< 10s', 'The messages had not been echoed within 10s');
|
||||
}, 10000);
|
||||
|
||||
ws.onmessage = function (event) {
|
||||
console.log('onmessage: ' + event.data);
|
||||
assert.strictEqual(lines[receiveIndex], event.data);
|
||||
receiveIndex++;
|
||||
if (receiveIndex === lines.length)
|
||||
ws.close();
|
||||
};
|
||||
|
||||
ws.onclose = function (event) {
|
||||
console.log('onclose');
|
||||
clearTimeout(timeout);
|
||||
assert.strictEqual(lines.length, receiveIndex, 'All messages were received');
|
||||
};
|
||||
|
||||
ws.onerror = function (error) {
|
||||
console.log('onerror');
|
||||
assert.ifError(error);
|
||||
};
|
||||
|
||||
ws.onopen = function () {
|
||||
console.log('onopen');
|
||||
var scheduleSendLine = function (line) {
|
||||
if (line < lines.length)
|
||||
setTimeout(function () {
|
||||
console.log('sending ' + lines[line]);
|
||||
ws.send(lines[line]);
|
||||
scheduleSendLine(line + 1);
|
||||
}, 200);
|
||||
};
|
||||
|
||||
console.log('sending ' + lines[0]);
|
||||
ws.send(lines[0]);
|
||||
scheduleSendLine(1);
|
||||
};
|
|
@ -10,7 +10,6 @@ var server = http.createServer(function (req, res) {
|
|||
});
|
||||
|
||||
server.addListener('upgrade', function (request, socket, head) {
|
||||
console.log(request.headers);
|
||||
var ws = new WebSocket(request, socket, head);
|
||||
|
||||
function schedule(line) {
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
|
||||
var WebSocket = require('faye-websocket')
|
||||
, http = require('http');
|
||||
|
||||
var server = http.createServer(function (req, res) {
|
||||
res.writeHead(400);
|
||||
res.end();
|
||||
});
|
||||
|
||||
server.addListener('upgrade', function (request, socket, head) {
|
||||
var ws = new WebSocket(request, socket, head);
|
||||
|
||||
ws.onmessage = function (event) {
|
||||
if (ws)
|
||||
ws.send(event.data);
|
||||
};
|
||||
|
||||
ws.onclose = function (event) {
|
||||
ws = null;
|
||||
};
|
||||
});
|
||||
|
||||
server.listen(process.env.PORT || 8888);
|
|
@ -0,0 +1,8 @@
|
|||
<configuration>
|
||||
<system.webServer>
|
||||
<handlers>
|
||||
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
|
||||
</handlers>
|
||||
<webSocket enabled="false" />
|
||||
</system.webServer>
|
||||
</configuration>
|
Загрузка…
Ссылка в новой задаче