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


Java WebSocketSession.close方法代码示例

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


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

示例1: handleTextMessage

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
protected void handleTextMessage(WebSocketSession session, TextMessage message) throws Exception {
	super.handleTextMessage(session, message);
	try {
		getClient(session,null);
		if (this.terminalClient != null ) {
			if ( !terminalClient.isClosed()) {
				terminalClient.write(message.getPayload());
			}else {
				session.close();
			}
		}
	} catch (Exception e) {
		session.sendMessage(new TextMessage("Sorry! opencron Terminal was closed, please try again. "));
		terminalClient.disconnect();
		session.close();
	}
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:19,代码来源:TerminalHandler.java

示例2: close

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public void close(WebSocketSession webSocketSession) {
    Replicator replicator = replicatorMap.remove(webSocketSession.getId());
    if (replicator != null) {
        try {
            replicator.close();
            webSocketSession.close();
        } catch (IOException e) {
            logger.warn(e.getMessage());
        }
    }
    RxClient rxClient = rxClientMap.get(webSocketSession.getId());
    if (rxClient != null) {
        rxClient.shutdown();
    }
    observableMap.remove(webSocketSession.getId());
    authMap.remove(webSocketSession.getId());
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:18,代码来源:RedisTextWebSocketHandler.java

示例3: handleTextMessage

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTextMessage(WebSocketSession session, TextMessage message) {
    try {
        log.info("[{}] Processing {}", session.getId(), message);
        SessionMetaData sessionMd = internalSessionMap.get(session.getId());
        if (sessionMd != null) {
            actorService.process(new TextPluginWebSocketMsg(sessionMd.sessionRef, message.getPayload()));
        } else {
            log.warn("[{}] Failed to find session", session.getId());
            session.close(CloseStatus.SERVER_ERROR.withReason("Session not found!"));
        }
        session.sendMessage(message);
    } catch (IOException e) {
        log.warn("IO error", e);
    }
}
 
开发者ID:osswangxining,项目名称:iotplatform,代码行数:17,代码来源:PluginWebSocketHandler.java

示例4: process

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void process() {

    BlockchainWebSocketHandler handler = new BlockchainWebSocketHandler();
    WebSocketClient client = new StandardWebSocketClient();
    try {
        WebSocketSession session = client.doHandshake(handler, WS_URI).get();
        session.sendMessage(new TextMessage("Hello World test."));
        session.close();
    } catch (Exception e) {
        logger.info(e);
    }
}
 
开发者ID:DanielJyc,项目名称:simpleblockchain,代码行数:14,代码来源:SendMessageClientImpl.java

示例5: 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

示例6: 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

示例7: 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

示例8: afterConnectionEstablished

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
	super.afterConnectionEstablished(session);
	String sshSessionId = (String) session.getAttributes().get(SSH_SESSION_ID);
	if (sshSessionId != null) {
		final Terminal terminal = TerminalContext.remove(sshSessionId);
		if (terminal!=null) {
			try {
				session.sendMessage(new TextMessage("Welcome to opencron Terminal! Connect Starting."));
				getClient(session,terminal);
				int cols = Integer.parseInt(session.getAttributes().get("cols").toString());
				int rows = Integer.parseInt(session.getAttributes().get("rows").toString());
				int width = Integer.parseInt(session.getAttributes().get("width").toString());
				int height = Integer.parseInt(session.getAttributes().get("height").toString());
				terminalClient.openTerminal(cols,rows,width,height);
				terminalService.login(terminal);
			} catch (Exception e) {
				if (e.getLocalizedMessage().replaceAll("\\s+", "").contentEquals("Operationtimedout")) {
					session.sendMessage(new TextMessage("Sorry! Connect timed out, please try again. "));
				} else {
					session.sendMessage(new TextMessage("Sorry! Operation error, please try again. "));
				}
				terminalClient.disconnect();
				session.close();
			}
		}else {
			this.terminalClient.disconnect();
			session.sendMessage(new TextMessage("Sorry! Connect failed, please try again. "));
			session.close();
		}
	}
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:33,代码来源:TerminalHandler.java

示例9: cleanSession

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
public static void cleanSession(String sessionId) throws IOException {
    WebSocketSession browserSession = sessionsTable.get(sessionsTable);
    if(browserSession != null){
        browserSession.close(CloseStatus.NO_STATUS_CODE);
        sessionsTable.remove(sessionId);
        LOGGER.info("Session {} cleaned.", sessionId);
    }
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:9,代码来源:WebSocketSessionsTable.java

示例10: handleTransportError

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTransportError(WebSocketSession session, Throwable exception)
    throws Exception {
  session.close(CloseStatus.SERVER_ERROR);
  logger.info("session closed: " + this);
}
 
开发者ID:sinaa,项目名称:train-simulator,代码行数:7,代码来源:WebSocketHandler.java

示例11: handleTransportError

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
	super.handleTransportError(session, exception);
	this.closeTerminal(session);
	session.close();
}
 
开发者ID:wolfboys,项目名称:opencron,代码行数:7,代码来源:TerminalHandler.java

示例12: handleMessageToClient

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
/**
 * Handle WAMP messages going back out to WebSocket clients.
 */
@Override
public void handleMessageToClient(WebSocketSession session, Message<?> message) {
	if (!(message instanceof WampMessage)) {
		logger.error("Expected WampMessage. Ignoring " + message + ".");
		return;
	}

	WampMessage wampMessage = (WampMessage) message;
	JsonFactory useFactory = this.jsonFactory;

	boolean isBinary = false;

	String acceptedProtocol = session.getAcceptedProtocol();
	if (acceptedProtocol != null) {
		if (acceptedProtocol.equals(WampSubProtocolHandler.MSGPACK_PROTOCOL)) {
			isBinary = true;
			useFactory = this.msgpackFactory;
		}
		else if (acceptedProtocol.equals(WampSubProtocolHandler.SMILE_PROTOCOL)) {
			isBinary = true;
			useFactory = this.smileFactory;
		}
		else if (acceptedProtocol.equals(WampSubProtocolHandler.CBOR_PROTOCOL)) {
			isBinary = true;
			useFactory = this.cborFactory;
		}

		try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
				JsonGenerator generator = useFactory.createGenerator(bos)) {
			generator.writeStartArray();
			wampMessage.serialize(generator);
			generator.writeEndArray();
			generator.close();

			if (isBinary) {
				session.sendMessage(new BinaryMessage(bos.toByteArray()));
			}
			else {
				session.sendMessage(new TextMessage(bos.toByteArray()));
			}

		}
		catch (Throwable ex) {
			// Could be part of normal workflow (e.g. browser tab closed)
			if (logger.isDebugEnabled()) {
				logger.debug("Failed to send WebSocket message to client in session "
						+ session.getId(), ex);
			}

			// Is this an outbound invocation message. In that case we need to feed
			// back
			// an error message
			if (message instanceof InvocationMessage) {
				ErrorMessage errorMessage = new ErrorMessage(
						(InvocationMessage) message, WampError.NETWORK_FAILURE);
				this.clientInboundChannel.send(errorMessage);
			}

			try {
				session.close(CloseStatus.PROTOCOL_ERROR);
			}
			catch (IOException e) {
				// Ignore
			}

		}
	}
	else {
		if (logger.isErrorEnabled()) {
			logger.error(
					"Failed to send WebSocket message to client because no accepted protocol "
							+ session.getId());
		}
	}
}
 
开发者ID:ralscha,项目名称:wamp2spring,代码行数:79,代码来源:WampSubProtocolHandler.java

示例13: handleTextMessage

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
protected void handleTextMessage(final WebSocketSession session, final TextMessage message) throws Exception {
    RxClient rxClient = rxClientMap.get(session.getId());
    if (rxClient == null) {
        session.close();
        return;
    }
    final String command = message.getPayload();
    if (command.equalsIgnoreCase("sync")) {
        sync(session);
    } else {
        String auth = authMap.get(session.getId());

        observableMap.get(session.getId())
                .subscribe(connection -> {
                    if (auth != null) {
                        connection.writeAndFlush("auth " + auth + "\r\n" + command + "\r\n");
                    } else {
                        connection.writeAndFlush(command + "\r\n");
                    }
                    connection.getInput()
                            .distinct()
                            .subscribe(response -> {
                                String requestMessage;
                                if (response instanceof DefaultLastBulkStringRedisContent) {
                                    DefaultLastBulkStringRedisContent content = (DefaultLastBulkStringRedisContent) response;
                                    byte[] bytes = new byte[content.content().readableBytes()];
                                    content.content().readBytes(bytes);
                                    requestMessage = new String(bytes);
                                } else if (response instanceof IntegerRedisMessage) {
                                    requestMessage = String.valueOf(((IntegerRedisMessage) response).value());
                                } else if (response instanceof ErrorRedisMessage) {
                                    requestMessage = ((ErrorRedisMessage) response).content();
                                } else if (response instanceof FullBulkStringRedisMessage) {
                                    requestMessage = "nil";
                                } else if (response instanceof SimpleStringRedisMessage) {
                                    requestMessage = ((SimpleStringRedisMessage) response).content();
                                } else if (response instanceof BulkStringHeaderRedisMessage || response instanceof DefaultBulkStringRedisContent || response instanceof ArrayHeaderRedisMessage) {
                                    return;
                                } else {
                                    requestMessage = response.toString();
                                }

                                try {
                                    session.sendMessage(new TextMessage(requestMessage));
                                } catch (IOException e) {
                                    logger.warn(e.getMessage());
                                }
                            });
                });
    }
}
 
开发者ID:wu191287278,项目名称:sc-generator,代码行数:53,代码来源:RedisTextWebSocketHandler.java

示例14: handleTransportError

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void handleTransportError(WebSocketSession session, Throwable exception) throws Exception {
    WebSocketSessionsTable.cleanSession("2");
    session.close(CloseStatus.SERVER_ERROR);
    LOGGER.info("...BrowserHandler connection {} closed for transportError.", session.getId());
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:7,代码来源:BrowserHandler.java

示例15: afterConnectionClosed

import org.springframework.web.socket.WebSocketSession; //导入方法依赖的package包/类
@Override
public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
    WebSocketSessionsTable.cleanSession("2");
    session.close(CloseStatus.NORMAL);
    LOGGER.info("...BrowserHandler connection {} closed.", session.getId());
}
 
开发者ID:peterjurkovic,项目名称:travel-agency,代码行数:7,代码来源:BrowserHandler.java


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