WebSocket编程

一、后端

类一:STOMPConnectEventListener implements ApplicationListener

前端建立websocket连接时,即connect时,会被该类监听到。在该类中,可以得到浏览器的sessionId,以及前端传过来的所有参数。

类二:STOMPDisconnectEventListener implements ApplicationListener

前端断开websocket连接时,即disconnect时,会被该类监听到。在该类中,可以得到浏览器的sessionId,但是不可以有其他参数。

类三:WebSocketService

用于createHeaders

类四:SocketSessionRegistry

connect时,建立sessionId;disconnect时,销毁sessionId。

类五:WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer

配置websocket的路径等配置信息,以及注册相关bean。

 

二、前端

方法一:connect()  连接服务器

//连接服务器
this.socket = new SockJS(serverURL + '/websocket-endpoint');
//该方法得到一个满足websocket定义的对象
this.stompClient = Stomp.over(this.socket);
this.stompClient.connect()

方法二:disconnect()断开服务器

  if (this.stompClient) {
    this.stompClient.disconnect()
  }

 

你可能感兴趣的:(Ark项目)