gpt4 book ai didi

c# - 用 Java 构建的基于 Spring 的代理的 Stomp WebSocket 客户端失败

转载 作者:行者123 更新时间:2023-11-30 17:45:13 24 4
gpt4 key购买 nike

我有一个用 Java(基于 Spring)构建的 Websocket Stomp 服务器。我的 JavaScript 客户端能够使用 Stomp over Web Socket 与服务器通信——没问题。

我正在尝试使用 WebSocket4Net 库构建 C# 客户端。谁能告诉我如何在 bytes[] 中构建 Stomp 消息帧并将它们发送到服务器?

OnOpen() 方法中,我正在执行以下操作:

String stompMsg = "CONNECT\n";
stompMsg += "accept-version:1.1,1.2\n\n";
stompMsg += "^@";

Byte[] bytesToSend = Encoding.UTF8.GetBytes(stompMsg);
websocketObj.Send(bytesToSend, 0, bytesToSend.Length);

我从服务器收到以下消息:

Failed to parse BinaryMessage payload - java.nio.HeapByteBuffer. Sending STOMP ERROR to client.

java.lang.IllegalArgumentException: Object of class [org.springframework.web.socket.BinaryMessage] must be an instance of class org.springframework.web.socket.TextMessage at org.springframework.util.Assert.isInstanceOf(Assert.java:339) at org.springframework.util.Assert.isInstanceOf(Assert.java:319) at org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageFromClient(StompSubProtocolHandler.java:189) at org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:307) at org.springframework.web.socket.handler.WebSocketHandlerDecorator.handleMessage(WebSocketHandlerDecorator.java:75) at org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.handleMessage(LoggingWebSocketHandlerDecorator.java:55) at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.handleMessage(ExceptionWebSocketHandlerDecorator.java:71) at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.handleBinaryMessage(StandardWebSocketHandlerAdapter.java:122) at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.access$100(StandardWebSocketHandlerAdapter.java:42) at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$4.onMessage(StandardWebSocketHandlerAdapter.java:88) at org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter$4.onMessage(StandardWebSocketHandlerAdapter.java:85) at org.apache.tomcat.websocket.WsFrameBase.sendMessageBinary(WsFrameBase.java:549) at org.apache.tomcat.websocket.WsFrameBase.processDataBinary(WsFrameBase.java:514) at org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:274) at org.apache.tomcat.websocket.WsFrameBase.processInputBuffer(WsFrameBase.java:116) at org.apache.tomcat.websocket.server.WsFrameServer.onDataAvailable(WsFrameServer.java:54) at org.apache.tomcat.websocket.server.WsHttpUpgradeHandler$WsReadListener.onDataAvailable(WsHttpUpgradeHandler.java:192) at org.apache.coyote.http11.upgrade.AbstractServletInputStream.onDataAvailable(AbstractServletInputStream.java:178) at org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:92) at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:601) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2430) at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2419) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:744)

如果您已经通过基于 spring 的 STOMP over Web Socket 服务器成功创建/使用任何 C# 客户端库,谁能提出建议?

最佳答案

@Artem - 非常感谢。\0 确实起到了作用。

websocket.Send("SUBSCRIBE\nid:sub-0\ndestination:/topic/mytopic\n\n\0");

关于c# - 用 Java 构建的基于 Spring 的代理的 Stomp WebSocket 客户端失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28163215/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com