【发布时间】:2016-04-18 03:24:18
【问题描述】:
这是我在 IBM Bluemix 上托管的服务器端代码,
const net = require('net');
const server = net.createServer((c) => { //'connection' listener
console.log('client connected');
c.on('end', () => {
console.log('client disconnected');
});
c.write('hello\r\n');
c.pipe(c);
});
server.listen(8124, () => { //'listening' listener
console.log('server bound');
});
我在本地使用下面的代码作为客户端,
var net = require('net');
var HOST = 'xxx.xx.xx.xx';
var PORT = xxxx;
var client = new net.Socket();
client.connect(PORT, HOST, function() {
console.log('CONNECTED TO: ' + HOST + ':' + PORT);
// Write a message to the socket as soon as the client is connected, the server will receive it as message from the client
client.write('I am Chuck Norris!');
});
// Add a 'data' event handler for the client socket
// data is what the server sent to this socket
client.on('data', function(data) {
console.log('DATA: ' + data);
// Close the client socket completely
client.destroy();
});
// Add a 'close' event handler for the client socket
client.on('close', function() {
console.log('Connection closed');
});
当我运行时,它会抛出错误。
events.js:141 投掷者; // 未处理的“错误”事件 ^
错误:连接 ETIMEDOUT xxx.xx.xx.xx:xxxx 在 Object.exports._errnoException (util.js:856:11) 在exports._exceptionWithHostPort (util.js:879:20) 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14) vivek@vivek-Latitude-E6220:/var/www/html/test/NODE/net$ 节点 client.js 事件.js:141 投掷者; // 未处理的“错误”事件 ^
错误:连接 ETIMEDOUT xxxx.xx.xx.xx:xxxx 在 Object.exports._errnoException (util.js:856:11) 在exports._exceptionWithHostPort (util.js:879:20) 在 TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
当我在本地运行服务器代码时,它运行良好。请帮我找出错误。
【问题讨论】:
-
指定端口是否已从 Bluemix 打开?还是服务器、客户端或网络防火墙阻止了连接?
-
@GalacticCowboy。该特定端口未打开。我发现这就是问题所在。但我不知道如何打开那个端口。所以我在 aws 中托管了我的应用程序并打开了那个端口。现在它正在工作。如果您知道如何在 IBM Bluemix 上打开端口。请将其发布为答案。
-
我没有使用 Bluemix 的经验,抱歉。我希望有办法,但我根本不知道他们的系统。
标签: javascript node.js sockets websocket ibm-cloud