私はHerokuでNetty SecureChatServerの例を使用しています。 私は、次のProcfile内容にサーバを起動しています:Herokuのドキュメントに指定されているNetty port on Heroku
web: java -cp target/classes:target/dependency/* SecureChatServer -DPORT=$PORT
ザ・$ PORTは、ランダムにすべての起動時に割り当てられます。私はポートを試してみました
public final class SecureChatClient {
static final String HOST = System.getProperty("host", "xxxxxxxxxxxx.herokuapp.com");
static final int PORT = Integer.parseInt(System.getProperty("port", "29143"));
public static void main(String[] args) throws Exception {
// Configure SSL.
final SslContext sslCtx = SslContextBuilder.forClient()
.trustManager(InsecureTrustManagerFactory.INSTANCE).build();
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.handler(new SecureChatClientInitializer(sslCtx));
// Start the connection attempt.
Channel ch = b.connect(HOST, PORT).sync().channel();
// Read commands from the stdin.
ChannelFuture lastWriteFuture = null;
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
for (;;) {
String line = in.readLine();
if (line == null) {
break;
}
// Sends the received line to the server.
lastWriteFuture = ch.writeAndFlush(line + "\r\n");
// If user typed the 'bye' command, wait until the server closes
// the connection.
if ("bye".equals(line.toLowerCase())) {
ch.closeFuture().sync();
break;
}
}
// Wait until all messages are flushed before closing the channel.
if (lastWriteFuture != null) {
lastWriteFuture.sync();
}
} finally {
// The connection is closed automatically on shutdown.
group.shutdownGracefully();
}
}
}
:私は次のようにサーバに接続しようとしているクライアントから
2016-07-05T07:16:04.815889+00:00 heroku[api]: Deploy 1d48bff by [...........]
2016-07-05T07:16:04.815960+00:00 heroku[api]: Release v27 created by [...........]
2016-07-05T07:16:05.032420+00:00 heroku[web.1]: Restarting
2016-07-05T07:16:05.033110+00:00 heroku[web.1]: State changed from up to starting
2016-07-05T07:16:07.437424+00:00 heroku[web.1]: Starting process with command `java -cp target/classes:target/dependency/* SecureChatServer -DPORT=29143`
2016-07-05T07:16:07.859601+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2016-07-05T07:16:09.011911+00:00 app[web.1]: Setting JAVA_TOOL_OPTIONS defaults based on dyno size. Custom settings will override them.
2016-07-05T07:16:09.015289+00:00 app[web.1]: Picked up JAVA_TOOL_OPTIONS: -Xmx350m -Xss512k -Dfile.encoding=UTF-8
2016-07-05T07:16:09.090952+00:00 app[web.1]: Port is: 29143
2016-07-05T07:16:09.810678+00:00 heroku[web.1]: Process exited with status 143
2016-07-05T07:16:09.894360+00:00 app[web.1]: Jul 05, 2016 7:16:09 AM io.netty.handler.logging.LoggingHandler bind
2016-07-05T07:16:09.898395+00:00 app[web.1]: Jul 05, 2016 7:16:09 AM io.netty.handler.logging.LoggingHandler channelActive
2016-07-05T07:16:09.892003+00:00 app[web.1]: INFO: [id: 0x4b5aac8d] REGISTERED
2016-07-05T07:16:09.898405+00:00 app[web.1]: INFO: [id: 0x4b5aac8d, L:/0:0:0:0:0:0:0:0:29143] ACTIVE
2016-07-05T07:16:09.894374+00:00 app[web.1]: INFO: [id: 0x4b5aac8d] BIND: 0.0.0.0/0.0.0.0:29143
2016-07-05T07:16:09.891990+00:00 app[web.1]: Jul 05, 2016 7:16:09 AM io.netty.handler.logging.LoggingHandler channelRegistered
2016-07-05T07:16:10.189332+00:00 app[web.1]: Jul 05, 2016 7:16:10 AM io.netty.handler.logging.LoggingHandler channelRead
2016-07-05T07:16:10.189343+00:00 app[web.1]: INFO: [id: 0x4b5aac8d, L:/0:0:0:0:0:0:0:0:29143] RECEIVED: [id: 0x992ddc07, L:/172.17.81.74:29143 - R:/172.17.81.73:31347]
2016-07-05T07:16:10.190954+00:00 app[web.1]: Jul 05, 2016 7:16:10 AM io.netty.handler.logging.LoggingHandler channelRead
2016-07-05T07:16:10.190970+00:00 app[web.1]: INFO: [id: 0x4b5aac8d, L:/0:0:0:0:0:0:0:0:29143] RECEIVED: [id: 0x1623ff10, L:/172.17.81.74:29143 - R:/172.17.81.73:31352]
2016-07-05T07:16:10.202144+00:00 heroku[web.1]: State changed from starting to up
2016-07-05T07:16:16.107796+00:00 app[web.1]: Jul 05, 2016 7:16:16 AM io.netty.handler.logging.LoggingHandler channelRead
2016-07-05T07:16:16.107806+00:00 app[web.1]: INFO: [id: 0x4b5aac8d, L:/0:0:0:0:0:0:0:0:29143] RECEIVED: [id: 0x668619db, L:/172.17.81.74:29143 - R:/172.17.81.73:32792]
:サーバーを展開した後
は罰金以下のログを起動しているようです80、8080、443、29143など ポート443で何とか接続しますが、期待されるような歓迎の挨拶はありません。 私は次の応答を得るポート443にメッセージを送信する場合:私が得るポート29143で
HTTP/1.1 400 Bad Request
Connection: close
Server: Cowboy
Date: Tue, 05 Jul 2016 07:37:17 GMT
Content-Length: 0
:
Exception in thread "main" java.net.ConnectException: Connection refused: no further information: xxxxxxxxxxxx.herokuapp.com/xxx.xx.xxx.x:29143
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:338)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:580)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:504)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:418)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:390)
at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:742)
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:145)
at java.lang.Thread.run(Unknown Source)
Herokuのルーターから400リクエストが送信されている必要があります。NettyクライアントをMeteorアプリケーションに接続しようとしましたが、同じ400応答が返されました。 –