本文整理汇总了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));
}
}