Spring 4 WebSocket 配置端口 [英] Spring 4 WebSocket configure port

查看:186
本文介绍了Spring 4 WebSocket 配置端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Spring 4 我需要配置 WebSocket 使用 HTTP 以外的其他端口.换句话说,默认用户访问 HTTP 和 WebSocket 如下:

Using Spring 4 I need configure WebSocket use other port than HTTP. In other words by default user access to HTTP and WebSocket as follow:

http://server:9090/
ws://server:9090/

但我需要执行以下操作:

But I need do the follow:

http://server:9090/
ws://server:9999/

在代码中我只有以下内容:

In code I have only following:

@Configuration
@EnableWebSocket
public class WebSocketConfig
    implements WebSocketConfigurer { 

我还有处理程序:

Handler extends TextWebSocketHandler {

Spring有这种能力吗?

Is there such ability in Spring?

推荐答案

AFAIK 所有当前的 websockets 实现都依赖于通过 HTTP 的握手.握手后,现有连接升级.你没有得到一个新的,端口保持不变.基本上所有的 websocket 连接都是从 HTTP 连接开始的.

AFAIK all current implementations of websockets depend on a handshake via HTTP. After the handshake the existing connection is upgraded. You don't get a new one and the port stays the same. Basically all websocket connections start as HTTP connections.

顺便说一下,端口、IP 地址等是服务器的主题,而不是应用程序本身.

As a side note the ports, IP addresses etc. are subject of the server, not the application itself.

可能可以配置您的服务器,以便两个端口可用于应用程序,但它们都可用于 HTTP 和 websocket.另一方面,这可能对您的情况有用.

It might be possible to configure your server so that two ports can be used for an application, but they would both be used for HTTP and websocket alike. On the other hand this might be useful in your situation.

这篇关于Spring 4 WebSocket 配置端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆