Java Code Examples for org.springframework.web.socket.WebSocketMessage

Following code examples demonstrate how to use org.springframework.web.socket.WebSocketMessagefrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.web.socket.WebSocketMessageand various code implementation of this class.

	public WebSocketMessage<?> replyMessage(String userId, WebSocketMessage<?> message) {
		Object messCont=message.getPayload();
		if(!(messCont instanceof String))
			return null;
		return new TextMessage("普通回复<"+message.getPayload()+">的消息");
	} 


	public WebSocketMessage<?> getMessage(String userId) {
		
		return null;
	} 

	public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
		logger.info("{}로 부터 {} 받음", session.getId(), message.getPayload());
	    for (WebSocketSession sess : sessionList) {
	      sess.sendMessage(new TextMessage(session.getId() + " : " + message.getPayload()));
	    }
	} 

	public WebSocketMessage<?> getMessage(String userId) {
		
		return null;
	} 

	public WebSocketMessage<?> replyMessage(String userId, WebSocketMessage<?> message) {
		Object messCont=message.getPayload();
		if(!(messCont instanceof String))
			return null;
		return new TextMessage("通知回复<"+message.getPayload()+">的消息");
	} 

    public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
        log.debug("session send msy. session: {}, msg: {}", session.getId(), message.getPayload().toString());
        BaseUser user = getUser(session);
        if (user == null && StringUtils.isBlank(message.getPayload().toString())) return;
        SocketObject obj = JsonMapper.nonDefaultMapper().fromJson(message.getPayload().toString(), SocketObject.class);
        
        socketManager.message(user, obj);
    } 

    public void sendMsgToAllUsers(WebSocketMessage<?> message) throws Exception{
        for (WebSocketSession user : users) {
            user.sendMessage(message);
        }
    } 

	public void handleMessage(WebSocketSession session, WebSocketMessage<?> message) throws Exception {
		
		super.handleMessage(session, message);
	} 

Advertisement
Advertisement