user4497170 user4497170 - 1 year ago 103
C# Question

Stomp WebSocket Client for a Spring based broker built in Java is failing

I have a Websocket Stomp server built in Java (Spring based). My JavaScript client is able to talk to the server using Stomp over Web Socket - no issues.

I'm trying to use the WebSocket4Net library to build the C# client. Can anyone please tell me how can I build the Stomp message frames in bytes[] and send them to the server?

In the

OnOpen()
method, I'm doing the following:

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);


I get the following message from server:


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)


Can anyone please suggest if you have successfully created / used any C# client library with a spring based STOMP over Web Socket server?

Answer Source

@Artem - Thank you SO much. The \0 indeed did the trick.

websocket.Send("SUBSCRIBE\nid:sub-0\ndestination:/topic/mytopic\n\n\0");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download