當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。