This commit is contained in:
Tomasz Janczuk 2012-09-11 16:50:23 -07:00
Родитель 8184cc555f
Коммит 73d1082e5f
5 изменённых файлов: 89 добавлений и 1 удалений

Просмотреть файл

@ -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>