我有两个在本地计算机上相互通信的应用程序。它的设计方式是,每当客户端发送数据时,它都会创建一个连接,然后客户端关闭该连接。
问题是服务器端的关闭连接未被破坏,导致内存泄漏。
这是服务器代码:
var server = http.createServer(function(request, response) {
// we don't have to implement anything.
});
server.listen(0, 'localhost', function() {});
// create the server
var wsServer = new WebSocketServer({
httpServer: server
});
// WebSocket server
wsServer.on('request', function(request) {
connection = request.accept(null, request.origin);
connection.on('message', function(message) {
// Calling some function to handle message
});
connection.on('close', function(connection) {
// I am getting this event on connection close by client
// what should I do so that connection destroy and
// doesn't cause a memory leak?
});
});
有人知道在这种情况下我能做什么吗?
注意:我无法更改服务器-客户端交互模型。