[英]Windows Server 2012, Apache Tomcat, Spring MVC: Websocket connection blocked for external IP
We've deployed our Spring MVC web application on Windows Server 2012 . 我们已经在Windows Server 2012上部署了Spring MVC Web应用程序。 Our web-app uses Spring Websockets for updates with stomp.js and sock.js .
我们的网络应用使用Spring Websockets通过stomp.js和sock.js进行更新。
Our websocket configuration: 我们的websocket配置:
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/calcApp");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/add").setAllowedOrigins("*").withSockJS();
}
}
Websocket works on localhost and logs are following: Websocket在本地主机上工作 ,日志如下:
Opening Web Socket...
Web Socket Opened...
>>> CONNECT
accept-version:1.1,1.0
heart-beat:10000,10000
<<< CONNECTED
version:1.1
heart-beat:0,0
user-name:admin
connected to server undefined
>>> SUBSCRIBE
id:sub-0
destination:/topic/resident
...
Strangely, it doesn't work when I enter external ip , on same machine and browser : 奇怪的是,当我在同一台机器和浏览器上输入external ip时,它不起作用:
Opening Web Socket...
WebSocket connection to 'ws://192.168.5.50:8080/autopark/add/629/i148hb1c/websocket' failed: WebSocket is closed before the connection is established.
Whoops! Lost connection to undefined
We thought that for external access , there is some firewall and totally disabled it: 我们认为,对于外部访问 ,有一些防火墙并完全禁用了它:
But it didn't solve our problem. 但这并不能解决我们的问题。
How can we solve this issue? 我们如何解决这个问题?
I'm not really sure and not a spring expert. 我不太确定,不是春季专家。
but it seems you need to call the server by a domain name over its ip addr which is logical. 但是似乎您需要通过其IP地址上的域名来调用服务器,这是合乎逻辑的。
Since an ip would be used for more than one domain, so it seems the context need to know which context should be called(even if one) in spring context. 由于一个ip将用于多个域,因此似乎上下文需要知道应该在spring上下文中调用哪个上下文(即使是一个)。
in other word, calling the context by ip would confuse the spring context to select/invoke which context/domain, so it refuses the connection. 换句话说,通过ip调用上下文会混淆spring上下文来选择/调用哪个上下文/域,因此它拒绝连接。
have atry, binf the 192.168.5.50
to a domain name, then try to call the path using the domain(not ip). 尝试将
192.168.5.50
绑定到一个域名,然后尝试使用该域(而非ip)调用路径。 Hope it works this way. 希望它能这样工作。
The first step in debugging this would be verifying that your application server is actually listening on the external interface. 调试的第一步将是验证您的应用服务器实际上是在外部接口上进行侦听。
You can verify what IP your container is bound to by looking for 8080 entries in the output of netstat. 您可以通过在netstat的输出中查找8080条目来验证容器绑定的IP。
netstat -a -n -o | find "8080"
The next step should be verifying an external computer can "see" the port on the external IP. 下一步应该是验证外部计算机可以“看到”外部IP上的端口。 There are various ways to do this, but using the telnet command will suffice.
有多种方法可以执行此操作,但是使用telnet命令就足够了。
telnet 192.168.5.50 8080
If we get to this point, then there is likely an issue with the configuration of the application itself. 如果到此为止,则应用程序本身的配置可能存在问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.