return createSocket(URI.create(uri), timeout);
/** * Create a WebSocket. * * <p> * This method is an alias of {@link #createSocket(URL, int) createSocket}{@code * (url, }{@link #getConnectionTimeout()}{@code )}. * </p> * * @param url * The URL of the WebSocket endpoint on the server side. * * @return * A WebSocket. * * @throws IllegalArgumentException * The given URL is {@code null} or failed to be converted into a URI. * * @throws IOException * Failed to create a socket. Or, HTTP proxy handshake or SSL * handshake failed. */ public WebSocket createSocket(URL url) throws IOException { return createSocket(url, getConnectionTimeout()); }
try { this.webSocket = new WebSocketFactory().createSocket(webSocketServer);
private void connect(String url) { WebSocketFactory factory = new WebSocketFactory(); if (proxy != null) { ProxySettings settings = factory.getProxySettings(); settings.setHost(proxy.getHostName()); settings.setPort(proxy.getPort()); } try { socket = factory.createSocket(url) .addHeader("Accept-Encoding", "gzip") .addListener(this); socket.connect(); } catch (IOException | WebSocketException e) { //Completely fail here. We couldn't make the connection. throw new RuntimeException(e); } }
/** * Opens a connection to the server over websocket * * @param isReconnect whether this is a re-connect attempt or not */ private void openConnection(final boolean isReconnect) { if (isReconnect) { if (mConnected) { initConnection(mSessionID); return; } } // create a new WebSocket connection for the data transfer try { mWebSocket = new WebSocketFactory().setConnectionTimeout(30000).createSocket(mServerUri); } catch (final IOException e) { mCallbackProxy.onException(e); } mWebSocket.setMissingCloseFrameAllowed(true); mWebSocket.setPingInterval(25 * 1000); mWebSocket.addListener(mWebSocketListener); mWebSocket.connectAsynchronously(); }
WebSocketFactory factory = new WebSocketFactory(); String webSocketUri = getGateway(api) + "?encoding=json&v=" + Javacord.DISCORD_GATEWAY_VERSION; Proxy proxy = api.getProxy().orElseGet(() -> { String proxyHost = proxyInetAddress.getHostString(); int proxyPort = proxyInetAddress.getPort(); ProxySettings proxySettings = factory.getProxySettings(); proxySettings.setHost(proxyHost).setPort(proxyPort); factory.setSSLSocketFactory(new TrustAllTrustManager().createSslSocketFactory()); WebSocket websocket = factory.createSocket(webSocketUri); this.websocket.set(websocket); websocket.addHeader("Accept-Encoding", "gzip");
public Socket(String URL) { this.URL = URL; factory = new WebSocketFactory().setConnectionTimeout(5000); counter = new AtomicInteger(1); acks = new HashMap<>(); channels = new ArrayList<>(); adapter = getAdapter(); headers = new HashMap<>(); putDefaultHeaders(); }
this.gatewayPoolProvider = gatewayPoolProvider; this.callbackPoolProvider = callbackPoolProvider; this.wsFactory = wsFactory == null ? new WebSocketFactory() : wsFactory; this.executor = createExecutor(threadFactory); this.controller = controller == null ? new SessionControllerAdapter() : controller;
try { this.webSocket = new WebSocketFactory().createSocket(webSocketServer);
WebSocketFactory factory = new WebSocketFactory(); if (proxy != null) ProxySettings settings = factory.getProxySettings(); settings.setHost(proxy.getHostName()); settings.setPort(proxy.getPort()); socket = factory.createSocket(wssEndpoint) .addListener(this) .connect();
/** * Create a WebSocket. * * <p> * This method is an alias of {@link #createSocket(String, int) * createSocket}{@code (uri, }{@link #getConnectionTimeout()}{@code )}. * </p> * * @param uri * The URI of the WebSocket endpoint on the server side. * * @return * A WebSocket. * * @throws IllegalArgumentException * The given URI is {@code null} or violates RFC 2396. * * @throws IOException * Failed to create a socket. Or, HTTP proxy handshake or SSL * handshake failed. */ public WebSocket createSocket(String uri) throws IOException { return createSocket(uri, getConnectionTimeout()); }
WebSocketFactory wsFactory = this.wsFactory == null ? new WebSocketFactory() : this.wsFactory;
return createSocket(url.toURI(), timeout);
sentMessageSet.clear(); mConnection = new WebSocketFactory() .createSocket("wss://ws.blockchain.info/inv") .addHeader("Origin", "https://blockchain.info").recreate() .addListener(new WebSocketAdapter() {
String query = uri.getRawQuery(); return createSocket(scheme, userInfo, host, port, path, query, timeout);
/** * Create a WebSocket. * * <p> * This method is an alias of {@link #createSocket(String, int) * createSocket}{@code (uri, }{@link #getConnectionTimeout()}{@code )}. * </p> * * @param uri * The URI of the WebSocket endpoint on the server side. * * @return * A WebSocket. * * @throws IllegalArgumentException * The given URI is {@code null} or violates RFC 2396. * * @throws IOException * Failed to create a socket. Or, HTTP proxy handshake or SSL * handshake failed. */ public WebSocket createSocket(String uri) throws IOException { return createSocket(uri, getConnectionTimeout()); }
WebSocket instance = mWebSocketFactory.createSocket(getURI(), timeout);
/** * Create a WebSocket. * * <p> * This method is an alias of {@link #createSocket(URL, int) createSocket}{@code * (url, }{@link #getConnectionTimeout()}{@code )}. * </p> * * @param url * The URL of the WebSocket endpoint on the server side. * * @return * A WebSocket. * * @throws IllegalArgumentException * The given URL is {@code null} or failed to be converted into a URI. * * @throws IOException * Failed to create a socket. Or, HTTP proxy handshake or SSL * handshake failed. */ public WebSocket createSocket(URL url) throws IOException { return createSocket(url, getConnectionTimeout()); }
protected void startConnection() { if (!reconnecting && socket != null) throw new IllegalStateException("Somehow, someway, this AudioWebSocket has already attempted to start a connection!"); try { socket = getJDA().getWebSocketFactory() .createSocket(wssEndpoint) .addListener(this); changeStatus(ConnectionStatus.CONNECTING_AWAITING_WEBSOCKET_CONNECT); socket.connectAsynchronously(); } catch (IOException e) { LOG.warn("Encountered IOException while attempting to connect: {}\nClosing connection and attempting to reconnect.", e.getMessage()); this.close(ConnectionStatus.ERROR_WEBSOCKET_UNABLE_TO_CONNECT); } }