无法连接到CloudFoundry上的TCP服务器(localhost node.js正常工作) [英] cannot connect to TCP server on CloudFoundry (localhost node.js works fine)

查看:96
本文介绍了无法连接到CloudFoundry上的TCP服务器(localhost node.js正常工作)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法连接到在CloudFoundry上运行的TCP服务器示例。在本地node.js安装上运行我的app.js文件时,它工作正常。具体来说,当我使用vmc push运行CloudFoundry时,该服务会启动并且不会崩溃。某些IP连接到它,断开连接,据我所知,该服务一直在运行。

I have trouble connecting to my TCP server example running on CloudFoundry. When running my app.js file on a local node.js installation, it works just fine. Specifically, when I run the CloudFoundry by using vmc push, the service starts and does not crash. Some IP connects to it, disconnects and as far as I can tell, the service keeps running.

我只是不能使用 telnet或 nc连接到它(请注意,当将它们定向到localhost node.js服务器时,它们都可以正常工作。

I just cannot connect to it using using neither "telnet" nor "nc" (note both of these work fine when directed towards the localhost node.js server.

这将失败:

> nc themagicsandbox2.cloudfoundry.com 8124

> nc localhost 8124
hello from TCP server! (intended reply)

我的代码在此处提交,Cloud Foundry stdout.log在其下方提交。

My code is submitted here and the Cloud Foundry stdout.log is submitted below it.

代码:

myTrace('loaded'); // myTrace prepends timestamp to text and sends to console.log

var tcpServer = require('net').createServer(function(sock) { //'connection' listener
    sock.on('connect', function() {
        myTrace('client ' + sock.remoteAddress + ':' + sock.remotePort +' connected');
        sock.write('hello from TCP server!\r\n');
        sock.pipe(sock);
      });

    sock.on('end', function() {
        myTrace('client disconnected');
      });
  });



tcpServer.listen(8124, process.env.VCAP_APP_HOST || "localhost");

tcpServer.on('listening', function() {
      myTrace('server is listening - bound!');
    });

tcpServer.on('error', function(err) {
     myTrace('server err: ' + err);
     if (err.code == 'EADDRINUSE') {
       myTrace('Address in use, retrying ...');
       setTimeout(function() {
           tcpServer.close(function (err) {
               myTrace('server.close: ' + err);
             });
           tcpServer.listen(SLIDEIN_TCP_PORT, process.env.VCAP_APP_HOST || "localhost");
         }, 1000);
     }
  });

tcpServer.on('close', 
          function() {
            myTrace('server has closed');
             });

stdout.log(CloudFoundry):

stdout.log (CloudFoundry):

Getting file contents... OK

Fri Mar 15 2013 11:59:02 GMT+0000 (UTC) loaded
Fri Mar 15 2013 11:59:02 GMT+0000 (UTC) server is listening - bound!
Fri Mar 15 2013 11:59:03 GMT+0000 (UTC) client 172.30.50.10:31840 connected
Fri Mar 15 2013 11:59:03 GMT+0000 (UTC) client disconnected

stdout(localhost node.js):

stdout (localhost node.js):

Fri Mar 15 2013 12:57:39 GMT+0100 (CET) loaded
Fri Mar 15 2013 12:57:39 GMT+0100 (CET) server is listening - bound!
Fri Mar 15 2013 12:57:53 GMT+0100 (CET) client 127.0.0.1:52260 connected
Fri Mar 15 2013 12:57:59 GMT+0100 (CET) client disconnected
Fri Mar 15 2013 12:58:00 GMT+0100 (CET) client 127.0.0.1:52261 connected
Fri Mar 15 2013 12:58:01 GMT+0100 (CET) client disconnected


推荐答案

这是因为请求是使用主机头路由到您的应用程序的,而这两个netcat都不或telnet发送。与其中任何一个发出请求时,您都可能会从路由器获得504。

That's because requests are routed to your application using the host header, neither of which netcat or telnet send. When making the request with either of those you will probably get a 504 back from the router.

这篇关于无法连接到CloudFoundry上的TCP服务器(localhost node.js正常工作)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆