Java WebSocket Client Spring引导(Java WebSocket Client Spring boot)
我想创建一个与Web套接字客户端连接到Web套接字服务器的Spring引导应用程序。
作为例子,我使用了Spring Boot中的入门指南。
https://spring.io/guides/gs/messaging-stomp-websocket/
在这个例子中,您使用spring引导创建一个web套接字服务器,并使用JavaScript连接到它。
我想运行该服务器并使用另一个创建WebSocketClient对象的弹簧启动应用程序连接到它。
这是我在Spring Boot客户端应用程序中创建的WebSocketClientConfiguration类
@Configuration @EnableWebSocketMessageBroker public class WebSocketClientConfig { @Bean public WebSocketClient webSocketClient() { final WebSocketClient client = new StandardWebSocketClient(); final WebSocketStompClient stompClient = new WebSocketStompClient(client); stompClient.setMessageConverter(new MappingJackson2MessageConverter()); final StompSessionHandler sessionHandler = new MyStompSessionHandler(); stompClient.connect("ws://localhost:8080", sessionHandler); return client; } }
但是在我的类MyStompSessionHandler中,在handleTransportError方法中,我可以看到异常是
javax.websocket.DeploymentException: The HTTP response from the server [200] did not permit the HTTP upgrade to WebSocket
任何想法我做错了什么?
I want to create a spring boot app with a web socket client that connects to a web socket server.
As an example, I used the Getting Started guide you can find in Spring Boot.
https://spring.io/guides/gs/messaging-stomp-websocket/
In this example, you create a web socket server using spring boot and you connect to it using JavaScript.
I want to run that server and connect to it using another spring boot application that creates a WebSocketClient object.
This is the WebSocketClientConfiguration class that I created in the Spring Boot client App
@Configuration @EnableWebSocketMessageBroker public class WebSocketClientConfig { @Bean public WebSocketClient webSocketClient() { final WebSocketClient client = new StandardWebSocketClient(); final WebSocketStompClient stompClient = new WebSocketStompClient(client); stompClient.setMessageConverter(new MappingJackson2MessageConverter()); final StompSessionHandler sessionHandler = new MyStompSessionHandler(); stompClient.connect("ws://localhost:8080", sessionHandler); return client; } }
But in my class MyStompSessionHandler, in handleTransportError method I can see that the exception is
javax.websocket.DeploymentException: The HTTP response from the server [200] did not permit the HTTP upgrade to WebSocket
Any idea what I am doing wrong?
原文:https://stackoverflow.com/questions/49590598
最满意答案
相关问答
更多-
iPhone:选择不同的行(IPhone: different row selected)[2022-11-09]
是的,你必须声明一个新的NSMutableArray (比如_selectedList )你的数据源数量。 用值为0的NSNumber填充它。 声明NSMutableArray *_selectedList; 在.h文件中(作为类成员) 在viewDidLoad或init方法中, _selectedList = [[NSMutableArray alloc] init]; for( int i = 0; i < [datasource count]; i++ ) { [_selectedList add ... -
Angular 5+ http发布(Angular 5+ http post issue)[2023-01-27]
有两种方法可以解决此问题。 如果您有权访问后端代码,则可以将其更改为忽略接受请求的ID字段。 而不是自动增加id字段。 你可以传递一个id,而不需要用户输入一个id。 npm install uuid --save import { v4 as uuid } from 'uuid'; mockNewTile = { id : uuid(), title: 'GO', description: 'Go is an open source programming lan ... -
如何在SVG终端的gnuplot 5+中将字体粗细设置为“粗体”?(How to set font weight to “bold” in gnuplot 5+ for SVG terminal?)[2022-07-09]
你很幸运, svg终端目前是唯一允许这样做的(?)终端。 您可以使用fname终端选项指定字体系列和字体粗细(使用font选项只能选择字体系列: set terminal svg standalone fname 'Arial bold' fsize 15 set xlabel 'xlabel' set ylabel 'ylabel' set output 'arial-bold.svg' plot x 但请注意,使用这些设置,您无法使用set label '{/:Normal Normal weight ... -
正如我在问题中评论的那样,这是iphone的safari上的一个错误 ,除了没有设置selected属性或没有使用optgroups ,没有什么optgroups 。 As I commented in the question, this is a bug on safari for iphone, and there's nothing to do but not setting a selected attribute, or not using optgroups.
-
另一种解决方案 int m = int.Parse(amount.Split('.')[0]); An alternative solution int m = int.Parse(amount.Split('.')[0]);
-
如何隐藏ios 4.3的UITabBar选择指标而不是5+?(How to hide the UITabBar selection indicator for ios 4.3 not for 5+?)[2022-06-10]
试试这个代码: // iOS 5.0+ [self.tabBar setSelectionIndicatorImage:[[[UIImage alloc] init]autorelease]]; // for earlier versions - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController { [s ... -
在设置值时,将隐藏它的输入添加* ngIf 否则只显示价值
{{cityName}} ... -
如何获得lambda函数不能在gcc 5+上工作[已关闭](How to get lambda functions not working on gcc 5+ [closed])[2022-04-10]
您需要将-std=c++11作为g++的标志之一: g++ -std=c++11 main.cpp -o listener && ./listener 现在,您将它作为./listener可执行文件的标志传递。 You need to put -std=c++11 as one of the flags for g++: g++ -std=c++11 main.cpp -o listener && ./listener Right now, you're passing it as a flag f ... -
Angular 5+的服务遗产(Service Heritage in Angular 5+)[2023-10-29]
我假设你想要实现某种在你的其他服务中保存一些共享逻辑的公共服务。 我也假设您不会在应用程序的任何部分注入此GlobalService ,只是扩展了这个部分。 如果是这种情况,则应从GlobalService删除@Injectable()装饰器。 这样做是为了告诉angular尝试在其构造函数中注入所有内容。 Angular知道如何注入http ,但它不知道如何注入name 。 因此,如果删除@Injectable() ,angular将忽略此服务。 您的其他服务将在其构造函数中注入http (如您在代码中所 ... -
当我创建一个新的通用项目时,我得到了这个: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization ...