Java 下拖配置TCP保持活动参数
我使用Undertow作为Java应用程序的服务器,我尝试使用 Undertow.Builder的setSocketOptions()方法(请参见下面的代码) 为了进行测试,我发送了一条消息,然后保持连接处于活动状态,而不发送任何内容,以便可以观察到TCP KeepAlive。 但不知何故,这些字段并没有被设置,因为我无法在tcpdump捕获中看到任何关于设置参数的保持活动的数据包 底拖是否支持这些参数的设置? 如果是,这是正确的方式来配置TCP Keep Alive参数,还是我遗漏了什么Java 下拖配置TCP保持活动参数,java,server,undertow,Java,Server,Undertow,我使用Undertow作为Java应用程序的服务器,我尝试使用 Undertow.Builder的setSocketOptions()方法(请参见下面的代码) 为了进行测试,我发送了一条消息,然后保持连接处于活动状态,而不发送任何内容,以便可以观察到TCP KeepAlive。 但不知何故,这些字段并没有被设置,因为我无法在tcpdump捕获中看到任何关于设置参数的保持活动的数据包 底拖是否支持这些参数的设置? 如果是,这是正确的方式来配置TCP Keep Alive参数,还是我遗漏了什么 @B
@Bean
public ServletWebServerFactory undertowFactory() {
UndertowServletWebServerFactory undertowFactory = new UndertowServletWebServerFactory();
// listen to http and enable http2
undertowFactory.addBuilderCustomizers((Undertow.Builder builder) -> {
builder.setWorkerThreads(maxWorkerThreads);
builder.addHttpListener(httpPort, "0.0.0.0");
builder.setServerOption(UndertowOptions.ENABLE_HTTP2, isHTTP2Enabled);
builder.setServerOption(UndertowOptions.IDLE_TIMEOUT, 3600000);
builder.setSocketOption(Options.KEEP_ALIVE, true);
builder.setSocketOption(Option.simple(StandardSocketOptions.class, "SO_KEEPALIVE", Boolean.class), true);
builder.setSocketOption(Option.simple(ExtendedSocketOptions.class, "TCP_KEEPINTERVAL", Integer.class), 10);
builder.setSocketOption(Option.simple(ExtendedSocketOptions.class, "TCP_KEEPIDLE", Integer.class), 10);
builder.setSocketOption(Option.simple(ExtendedSocketOptions.class, "TCP_KEEPCNT", Integer.class), 10);
});
logger.info("Undertow Max Worker Threads: " + maxWorkerThreads);
undertowFactory.addDeploymentInfoCustomizers(deploymentInfo -> {
deploymentInfo.addInitialHandlerChainWrapper(gracefulShutdown());
});
// redirect http to https
if (redirectHTTP == true) {
undertowFactory.addDeploymentInfoCustomizers(deploymentInfo -> {
deploymentInfo.addSecurityConstraint(new SecurityConstraint()
.addWebResourceCollection(new WebResourceCollection().addUrlPattern("/*"))
.setTransportGuaranteeType(TransportGuaranteeType.CONFIDENTIAL)
.setEmptyRoleSemantic(SecurityInfo.EmptyRoleSemantic.PERMIT))
.setConfidentialPortManager(exchange -> httpsPort);
});
}
return undertowFactory;
}