本文整理匯總了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);
}
}
示例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();
}
}
}
示例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);
}
示例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...");
}
示例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...");
}
示例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);
}
}
示例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));
}
}
示例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));
}
}