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

时间:2015-01-27 04:22:15

标签: c# stomp spring-websocket

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

我试图使用WebSocket4Net库来构建C#客户端。任何人都可以告诉我如何以字节[]构建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);

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

  

无法解析BinaryMessage有效负载 - java.nio.HeapByteBuffer。   将STOMP ERROR发送给客户端。

     

java.lang.IllegalArgumentException:类[org.springframework.web.socket.BinaryMessage]的对象必须是类org.springframework.web.socket.TextMessage的实例       在org.springframework.util.Assert.isInstanceOf(Assert.java:339)       在org.springframework.util.Assert.isInstanceOf(Assert.java:319)       在org.springframework.web.socket.messaging.StompSubProtocolHandler.handleMessageFromClient(StompSubProtocolHandler.java:189)       在org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.handleMessage(SubProtocolWebSocketHandler.java:307)       在org.springframework.web.socket.handler.WebSocketHandlerDecorator.handleMessage(WebSocketHandlerDecorator.java:75)       在org.springframework.web.socket.handler.LoggingWebSocketHandlerDecorator.handleMessage(LoggingWebSocketHandlerDecorator.java:55)       at org.springframework.web.socket.handler.ExceptionWebSocketHandlerDecorator.handleMessage(ExceptionWebSocketHandlerDecorator.java:71)       在org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.handleBinaryMessage(StandardWebSocketHandlerAdapter.java:122)       在org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter.access $ 100(StandardWebSocketHandlerAdapter.java:42)       在org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter $ 4.onMessage(StandardWebSocketHandlerAdapter.java:88)       在org.springframework.web.socket.adapter.standard.StandardWebSocketHandlerAdapter $ 4.onMessage(StandardWebSocketHandlerAdapter.java:85)       at org.apache.tomcat.websocket.WsFrameBase.sendMessageBinary(WsFrameBase.java:549)       在org.apache.tomcat.websocket.WsFrameBase.processDataBinary(WsFrameBase.java:514)       在org.apache.tomcat.websocket.WsFrameBase.processData(WsFrameBase.java:274)       在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)       在org.apache.coyote.http11.upgrade.AbstractProcessor.upgradeDispatch(AbstractProcessor.java:92)       at org.apache.coyote.AbstractProtocol $ AbstractConnectionHandler.process(AbstractProtocol.java:601)       在org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.doRun(AprEndpoint.java:2430)       在org.apache.tomcat.util.net.AprEndpoint $ SocketProcessor.run(AprEndpoint.java:2419)       在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)       at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)       在java.lang.Thread.run(Thread.java:744)

任何人都可以建议您是否已成功创建/使用任何带有基于Spring的STOMP over Web Socket服务器的C#客户端库?

1 个答案:

答案 0 :(得分:1)

@Artem - 非常感谢你。 \ 0确实做到了这一点。

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