[英]Java client cant connect with NodeJS server on heroku
So I have this Javascript server: 所以我有这个Javascript服务器:
const net = require('net');
var port = process.env.PORT || 3001;
net.createServer(function (sock){
console.log('CONNECTED: ' + sock.remoteAddress + ":" + sock.remotePort);
sock.on('data', function(data){
console.log(data.toString());
});
sock.on('close', function(data){
console.log('DISCONNECTED: ' + sock.remoteAddress + ":" + sock.remotePort);
});
sock.on('error', function(error){
console.log(error);
});
}).listen(port, '0.0.0.0');
console.log('Listening on: ' + port);
And I use this to connect my Java client: 我使用它来连接我的Java客户端:
public void connect () {
System.out.println("Connecting with: " + host + ":" + port);
try {
this.socket = new Socket(this.host, this.port);
System.out.println("Connected!");
} catch (IOException e) {
e.printStackTrace();
}
}
And it works when I try it local but whenever I upload it to heroku it never logs a CONNECTED message or any received data so I don't think it connects. 当我在本地尝试时,它可以工作,但是每当我将其上传到heroku时,它都不会记录CONNECTED消息或任何接收到的数据,因此我认为它不会连接。
I'm using this as ip/port to connect my client: .herokuapp.com:heroku.env.PORT not literally ofcourse, I use the port heroku gives to my application on launch since I do see the Listening on: message. 我使用它作为ip / port连接我的客户端:.herokuapp.com:heroku.env.PORT当然不是,我使用了heroku在启动时为应用程序提供的端口,因为我确实看到了Listening on:消息。
Am I doing something wrong? 难道我做错了什么? Or does heroku not support sockets? 还是heroku不支持套接字?
客户端应连接到<appname>.herokuapp.com
在端口80或443。 PORT
var为仅供内部结合。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.