我们已经将我们的Spring web应用程序部署在Windows 2012上。我们的网络应用程序使用Spring 进行stomp.js和sock.js的更新。
我们的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在本地主机上工作,日志如下所示:
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
...奇怪的是,当我输入外部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我们认为对于外部访问,存在一些防火墙,并且完全禁用了它:

但它并没有解决我们的问题。
我们如何解决这个问题呢?
发布于 2017-04-15 16:22:03
我不太确定,也不是春季专家。
但是,您似乎需要通过其ip addr通过域名调用服务器,这是合乎逻辑的。
由于ip将用于多个域,因此上下文似乎需要知道在spring上下文中应该调用哪个上下文(即使是一个上下文)。
换句话说,通过ip调用上下文将混淆spring上下文以选择/调用哪个上下文/域,因此它拒绝连接。
让atry,将192.168.5.50绑定到一个域名,然后尝试使用域(而不是ip)调用路径。希望是这样的。
发布于 2017-04-22 13:54:08
调试的第一步是验证应用程序服务器是否真的在监听外部接口。
您可以通过在netstat输出中查找8080个条目来验证容器绑定的IP。
netstat -a -n -o | find "8080"- If you don't see an entry bound to either 0.0.0.0 or the external IP, then we know it is a configuration issue with your application server.
- Example for embedded tomcat - [How to set a IP address to the tomcat?](https://stackoverflow.com/questions/21303941/how-to-set-a-ip-address-to-the-tomcat)
- Example for standalone tomcat - [How do you configure tomcat to bind to a single ip address (localhost) instead of all addresses?](https://stackoverflow.com/questions/18617/how-do-you-configure-tomcat-to-bind-to-a-single-ip-address-localhost-instead-o)
下一步应该是验证外部计算机可以“看到”外部IP上的端口。这样做有多种方法,但使用telnet命令就足够了。
telnet 192.168.5.50 8080
如果我们谈到这一点,那么应用程序本身的配置可能会出现问题。
https://stackoverflow.com/questions/43395903
复制相似问题