我有一個的WebSocket在初始化爲我的HTTP的模擬服務器文件中的一個如下:如何阻止Ember CLI的http-mock服務器在其中一個服務器文件中存在websockets時拋出錯誤?
var WebSocketServer = require('ws').Server;
var socketServer = new WebSocketServer({port: 13434, path: "/update"});
,後來我有以下的連接發生在文件中:
socketServer.on('connection', function(ws) {
ws.on('close', function(message) {
clearInterval(sendResults);
});
ws.on('message', function(message) {
handleClientMessage(ws, message);
});
sendResults = setInterval(function() {
ws.send(JSON.stringify(getResultsFromEntries()));
}, resultInterval);
});
但是,每當我編輯任何服務器文件我收到以下錯誤:
File changed: "mocks/entry.js"
Just getting started with Ember? Please visit http://localhost:4200/ember-getting-started to get going
events.js:141
throw er; // Unhandled 'error' event
^
Error: listen EADDRINUSE 0.0.0.0:13434
at Object.exports._errnoException (util.js:907:11)
at exports._exceptionWithHostPort (util.js:930:20)
at Server._listen2 (net.js:1250:14)
at listen (net.js:1286:10)
at net.js:1395:9
at nextTickCallbackWith3Args (node.js:453:9)
at process._tickCallback (node.js:359:17)
我猜我需要檢測文件更改何時發生並關閉curre nt websocket連接。在進程退出似乎沒有被調用,直到服務器死亡,然後process.on('exit',function(){})被稱爲服務器刷新的次數。它不會讓我感到困擾,因爲我有一個腳本,在腳本重新啓動後,如果腳本停止運行,但其他開發人員不喜歡編輯服務器文件時耗盡服務器。有任何想法嗎?
感謝您的迴應。關閉似乎沒有被調用時,一個服務器文件更改,但我確實設法得到它的工作。 – KroneckerDeIta