@Override public InetSocketAddress getRemoteAddress() { return this.delegate.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); }
@Test public void testGetRemoteAddress() throws Exception { URI uri = new URI("wss://localhost/abc"); WebSocketSession session = this.wsClient.doHandshake(this.wsHandler, this.headers, uri).get(); assertNotNull(session.getRemoteAddress()); assertEquals("localhost", session.getRemoteAddress().getHostName()); assertEquals(443, session.getLocalAddress().getPort()); }
@Override public void afterConnectionClosed(WebSocketSession theSession, CloseStatus theStatus) throws Exception { super.afterConnectionClosed(theSession, theStatus); ourLog.info("Closing WebSocket connection from {}", theSession.getRemoteAddress()); }
@Override public void afterConnectionEstablished(WebSocketSession theSession) throws Exception { super.afterConnectionEstablished(theSession); ourLog.info("Incoming WebSocket connection from {}", theSession.getRemoteAddress()); }
@ServerEndpoint (value="/mySillyApp", configurator= ..., decoders={...}) public class MySillyWebSocketServer { @OnOpen public void open (Session session, EndpointConfig config) { JsrSession jsrSession = (JsrSession) session; // import org.eclipse.jetty.websocket.jsr356.JsrSession; WebSocketSession webSocketSession = jsrSession.getWebSocketSession (); // import org.eclipse.jetty.websocket.common.WebSocketSession; String clientIPAddressString = webSocketSession.getRemoteAddress ().getHostString (); .... } ... }
@Override public InetSocketAddress getRemoteAddress() { return this.delegate.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { return this.delegate.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); }
@Override public InetSocketAddress getRemoteAddress() { Assert.state(this.webSocketSession != null, "WebSocketSession not yet initialized"); return this.webSocketSession.getRemoteAddress(); }
private void fatalError(WebSocketSession session, Exception exception) { try { session.close(CloseStatus.SESSION_NOT_RELIABLE); } catch (Exception ignored) {/*no-op*/} cancelAll(); log.warn(String.format("WebSocket session %s (%s) closed due to an exception", session.getId(), session.getRemoteAddress()), exception); }
private void fatalError(WebSocketSession session, Exception exception) { try { session.close(CloseStatus.SESSION_NOT_RELIABLE); } catch (Exception ignored) {/*no-op*/} cancelAll(); log.warn(String.format("WebSocket session %s (%s) closed due to an exception", session.getId(), session.getRemoteAddress()), exception); }
public HiveAuthentication.HiveAuthDetails getDetails(WebSocketSession session) { List<String> originList = session.getHandshakeHeaders().get(HttpHeaders.ORIGIN); List<String> authList = session.getHandshakeHeaders().get(HttpHeaders.AUTHORIZATION); String origin = originList == null || originList.isEmpty() ? null : originList.get(0); String auth = authList == null || authList.isEmpty() ? null : authList.get(0); return new HiveAuthentication.HiveAuthDetails(session.getRemoteAddress().getAddress(), origin, auth); } }
/** * 根据用户名删除客户端 * * @param pUserName */ public void removeClient(String pUserName) { if (mClients.containsKey(pUserName)) { WebSocketSession pClient = mClients.get(pUserName); String id = pClient.getId(); String vAddress = pClient.getRemoteAddress().getAddress().getHostAddress(); try { if (pClient.isOpen()) { pClient.close(); } } catch (Exception e) { } pClient = null; mClients.remove(pUserName); onRemoveClient(pUserName, id, vAddress); } }
protected void validLogin(WebSocketSession pWebSocketSession, ValidMessage pValidMessage) throws APPErrorException { //模拟登陆 SimpleSession session = new SimpleSession(); session.setHost(pWebSocketSession.getRemoteAddress().getHostName()); WebDelegatingSubject subject = new WebDelegatingSubject(null, true, "", session, null, null, getSecurityManager()); ThreadContext.bind(subject); getUserService().tokenLogin(pWebSocketSession.getRemoteAddress().getHostName(), pValidMessage.getUser(), pValidMessage.getToken()); //登录成功后 添加客户端 mClientFactory.addClient(pValidMessage.getUser(), pWebSocketSession); } @Override
@Override public void afterConnectionEstablished(WebSocketSession session) throws Exception { try { incNumConnectionsIfAllowed(); } catch (MaxNumberWsConnectionsReachedException e) { log.warn("Closed a WS connection because MAX_WS_CONNECTIONS={} limit reached", MAX_WS_CONNECTIONS); session.close(); } try { // We send this notification to the JsonRpcHandler when the JsonRpc // session is established, not when websocket session is established log.debug( "{} Client connection established from session={} uri={} headers={} acceptedProtocol={} attributes={}", label, session.getRemoteAddress(), session.getUri(), session.getHandshakeHeaders(), session.getAcceptedProtocol(), session.getAttributes()); } catch (Throwable t) { log.error("{} Exception processing afterConnectionEstablished in session={}", label, session.getId(), t); } }
@Override public Row render(Session session) { Row row = new Row(); String sessionId = session.getId(); Date creationTime = new Date(session.getCreationTime()); Date lastAccessedTime = new Date(session.getLastActivity()); String clientAddress = session.getSocket().getRemoteAddress().toString(); createCell(row, sessionId); createCell(row, clientAddress); createCell(row, creationTime); createCell(row, lastAccessedTime); if (session == ExecutionContext.getSession()) { row.setStyles("font-weight:bold;color:blue"); } return row; }