StompProtocolAndroid icon indicating copy to clipboard operation
StompProtocolAndroid copied to clipboard

How to get the stomp protocol data sent by the server to the client when the connection is successful? Do you need to subscribe to topic?

Open Arisono opened this issue 7 years ago • 0 comments

Client code

mStompClient.lifecycle()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(lifecycleEvent -> {
                    switch (lifecycleEvent.getType()) {
                        case OPENED:               
                            toast("connection success!");
                            Log.i(TAG, "This data comes from the server:"+JSON.toJSONString(lifecycleEvent));
                             
// How to get the stomp protocol data sent by the server to the client when the 
//connection is successful? Do you need to subscribe to topic?               
//                          mStompClient.send("/connectioned", "connectioned topic")
//                                    .compose(applySchedulers())
//                                    .subscribe(() -> {
//                                        Log.d(TAG, "send success!");
//                                    }, throwable -> {
//                                        Log.e(TAG, "send errors", throwable);
//                                        toast(throwable.getMessage());
//                                    });
                            break;

There is no message data sent by the server to the custom format of the client.

This data comes from the server:{"handshakeResponseHeaders":{"Connection":"upgrade","Date":"Tue, 26 Jun 2018 08:51:19 GMT","Sec-WebSocket-Accept":"Ocn01vRvUiTfnP9HVg55kNI6zy8=","Upgrade":"websocket"},"type":"OPENED"}

Server code:

`return new WebSocketHandlerDecorator(handler){

				@Override
				public void afterConnectionEstablished(
						WebSocketSession session) throws Exception {
					try {	
                                                    //send data			
						session.sendMessage(new WebSocketMessage<String>() {
                               
							@Override
							public String getPayload() {				
								return "CONNECT"
										+ "version:1.1,1.0"
										+ "heart-beat:5000,5000";
							}

							@Override
							public int getPayloadLength() {
								return 500;
							}

							@Override
							public boolean isLast() {				
								return false;
							}
						});
					} catch (Exception e) {			
						e.printStackTrace();
					}

					super.afterConnectionEstablished(session);
				}`

How does the client get the data sent by the server when the connection is successful?

Arisono avatar Jun 26 '18 09:06 Arisono