当前位置: 首页>>代码示例>>Java>>正文


Java WebSocketSession.isOpen方法代码示例

本文整理汇总了Java中org.springframework.web.socket.WebSocketSession.isOpen方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocketSession.isOpen方法的具体用法?Java WebSocketSession.isOpen怎么用?Java WebSocketSession.isOpen使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.springframework.web.socket.WebSocketSession的用法示例。


在下文中一共展示了WebSocketSession.isOpen方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendMsg

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public static void sendMsg() {
  try {
    List<TaskInfo> taskInfos = new LinkedList<>();
    for (Entry<String, HttpDownInfo> downInfoEntry : HttpDownServer.DOWN_CONTENT.entrySet()) {
      HttpDownInfo httpDownInfo = downInfoEntry.getValue();
      if (httpDownInfo.getTaskInfo().getStatus() != 0) {
        taskInfos.add(httpDownInfo.getTaskInfo());
      }
    }
    TextMessage message = new TextMessage(JSON.toJSONString(taskInfos));
    for (Entry<String, WebSocketSession> entry : HttpDownServer.WS_CONTENT.entrySet()) {
      WebSocketSession session = entry.getValue();
      if (session.isOpen()) {
        synchronized (session) {
          session.sendMessage(message);
        }
      }
    }
  } catch (Exception e) {
    HttpDownServer.LOGGER.warn("sendMsg",e);
  }
}
 
开发者ID:monkeyWie,项目名称:proxyee-down,代码行数:23,代码来源:WsUtil.java

示例2: sendMessageToUsers

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
/** 
 * 给所有在线用户发送消息 
 * 
 * @param message 
 */  
public void sendMessageToUsers(TextMessage message) {  
    for (WebSocketSession user : users) {  
        try {  
            if (user.isOpen()) {  
                user.sendMessage(message);  
            }  
        } catch (IOException e) {  
            e.printStackTrace();  
        }  
    }  
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:17,代码来源:BinaryGeometryTemplateSocketHandler.java

示例3: handleTransportError

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override  
public void handleTransportError(WebSocketSession webSocketSession, Throwable throwable) throws Exception {  
    if(webSocketSession.isOpen()){  
        webSocketSession.close();  
    }  
    logger.info("connenction error,close the connection...");  
    users.remove(webSocketSession);  
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:9,代码来源:BinaryGeometryTemplateSocketHandler.java

示例4: handleTransportError

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override  
    public void handleTransportError(WebSocketSession webSocketSession, Throwable throwable) throws Exception { 
    	users.remove(webSocketSession);
//        server.getLongActionManager().cancelLongActionByWebSocketSessionRelated(webSocketSession);
        if(webSocketSession.isOpen()){  
            webSocketSession.close();  
        }  
        logger.info("connenction error,close the connection...");  
    }
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:10,代码来源:StreamGeometrySocketHandler.java

示例5: handleTransportError

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTransportError(WebSocketSession webSocketSession, Throwable throwable) throws Exception {
	users.remove(webSocketSession);
	// server.getLongActionManager().cancelLongActionByWebSocketSessionRelated(webSocketSession);
	if (webSocketSession.isOpen()) {

		webSocketSession.close();
	}
	logger.info("connenction error,close the connection...");
}
 
开发者ID:shenan4321,项目名称:BIMplatform,代码行数:11,代码来源:GeometrySocketHandler.java

示例6: sendTo

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
/**
 * 单独发送给某人
 *
 * @param msg 信息
 * @param id  id
 */
public void sendTo(TextMessage msg, String id) {
    WebSocketSession session = MapUtils.getObject(clients, id);
    if (session == null || !session.isOpen()) {
        LOGGER.warn("将要发送给的session已不存在,{}", id);
        return;
    }
    try {
        session.sendMessage(msg);
    } catch (IOException e) {
        LOGGER.error("[DrawGuess]发送消息\"{}\"出错", msg.getPayload(), e);
    }
}
 
开发者ID:csdbianhua,项目名称:telemarket-skittle-alley,代码行数:19,代码来源:DrawGuessWebSocket.java

示例7: handleBinaryMessage

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception {
    WebSocketSession phoneSession = WebSocketSessionsTable.sessionsTable.get("2");

    if(phoneSession != null && phoneSession.isOpen()) {
        ByteBuffer echoMessage = message.getPayload();
        phoneSession.sendMessage(new BinaryMessage(echoMessage));
    }
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:10,代码来源:BrowserHandler.java

示例8: handleBinaryMessage

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) throws Exception {
    WebSocketSession browserSession = WebSocketSessionsTable.sessionsTable.get("1");
    if(browserSession != null && browserSession.isOpen()) {
        ByteBuffer echoMessage = message.getPayload();
        browserSession.sendMessage(new BinaryMessage(echoMessage));
    }
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:9,代码来源:VapiHandler.java


注:本文中的org.springframework.web.socket.WebSocketSession.isOpen方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。