Spring 4 WebSocket 配置端口

编程入门 行业动态 更新时间:2024-10-24 20:22:04
本文介绍了Spring 4 WebSocket 配置端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

使用 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 05:11:48,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1129024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:端口   Spring   WebSocket

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!