java - Writing a client to connect to websocket in spring boot -


i'm trying make websocketed based server/client application using spring boot.

the server accepts socket connection when recieves text message client process it, return data. server has websocket handler correctly process request.

public class datawebsockethandler extends textwebsockethandler {  private static logger logger = loggerfactory.getlogger(datawebsockethandler.class);  private final dataservice dataservice;  @autowired public datawebsockethandler(dataservice dataservice) {     this.dataservice = dataservice; }  @override public void afterconnectionestablished(websocketsession session) {     logger.debug("opened new session in instance " + this); }  @override public void handletextmessage(websocketsession session, textmessage message)         throws exception {     byte[] payload = this.dataservice.getdatabytes(message.getpayload());     session.sendmessage(new binarymessage(payload)); }  @override public void handletransporterror(websocketsession session, throwable exception)         throws exception {     session.close(closestatus.server_error); }  } 

and registered

@override public void registerwebsockethandlers(websockethandlerregistry registry) {     registry.addhandler(datawebsockethandler(), "/data").withsockjs(); } 

my problem is, have no idea how write client can connect server(assuming wrote server correctly) , extensions how send message , how receive data on client side.

i've failed find example of this, there plenty websocket written broadcasts clients subscribed socket, don't want.

the server uses embeded tomcat server.

i believe you're looking for

https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-websocket-jetty/src/main/java/samples/websocket/jetty/echo

this similar server side code..

https://github.com/spring-projects/spring-boot/blob/master/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/samplewebsocketsapplicationtests.java

and here client side.. using org.springframework.web.socket.client.standard.standardwebsocketclient ad othe configuration.

i believe can figure out rest ;)

cheers


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -