public void connect(String url) { try { mHttpClient= (OkHttpClient) Class.forName("com.squareup.okhttp.OkHttpClient").newInstance(); } catch (Exception e) { isSupportWebSocket =false; return; } mHttpClient.setConnectTimeout(10, TimeUnit.SECONDS); mHttpClient.setWriteTimeout(10, TimeUnit.SECONDS); // Disable timeouts for read mHttpClient.setReadTimeout(0, TimeUnit.MINUTES); Request request = new Request.Builder().url(url).build(); WebSocketCall call = WebSocketCall.create(mHttpClient, request); call.enqueue(this); }
public void connect(String url, Callback callback) { if (mHttpClient != null) { throw new IllegalStateException("DebugSocketClient is already initialized."); } mConnectCallback = callback; mHttpClient = new OkHttpClient(); mHttpClient.setConnectTimeout(30, TimeUnit.SECONDS); mHttpClient.setWriteTimeout(30, TimeUnit.SECONDS); // Disable timeouts for read mHttpClient.setReadTimeout(0, TimeUnit.MINUTES); if (!TextUtils.isEmpty(url)) { Request request = new Request.Builder().url(url).build(); WebSocketCall call = WebSocketCall.create(mHttpClient, request); call.enqueue(this); } }
/** * Opens a connection to the server over websocket * * @param isReconnect whether this is a re-connect attempt or not */ public void openConnection(final boolean isReconnect) { if (isReconnect) { if (isConnected()) { connect(mSessionID); return; } } OkHttpClient client = new OkHttpClient(); client.setConnectTimeout(1, TimeUnit.MINUTES); client.setReadTimeout(1, TimeUnit.MINUTES); client.setWriteTimeout(1, TimeUnit.MINUTES); HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BASIC); client.networkInterceptors().add(loggingInterceptor); Request request = new Request.Builder() .url(mServerUri) .build(); WebSocketCall.create(client, request).enqueue(mWebSocketObserver); }
/** * Creates a websocket that connects to the given URL. * * @param url where the websocket server is * @param headers headers to pass in the connect request * @return the websocket */ public WebSocketCall createWebSocketCall(String url, Map<String, String> headers) { String base64Credentials = buildBase64Credentials(); Request.Builder requestBuilder = new Request.Builder() .url(url) .addHeader("Authorization", "Basic " + base64Credentials) .addHeader("Accept", "application/json"); if (headers != null) { for (Map.Entry<String, String> header : headers.entrySet()) { requestBuilder.addHeader(header.getKey(), header.getValue()); } } Request request = requestBuilder.build(); WebSocketCall wsc = WebSocketCall.create(getHttpClient(), request); return wsc; }
public boolean connect(String url) { OkHttpClient httpClient = new OkHttpClient(); Request request = new Request.Builder().url(url).addHeader("sec-websocket-protocol", "echo-protocol").build(); WebSocketCall.create(httpClient, request).enqueue(new WXWebSocketListener(url)); return true; }
public void connect(String url, JSDebuggerCallback callback) { if (mHttpClient != null) { throw new IllegalStateException("JSDebuggerWebSocketClient is already initialized."); } mConnectCallback = callback; mHttpClient = new OkHttpClient(); mHttpClient.setConnectTimeout(10, TimeUnit.SECONDS); mHttpClient.setWriteTimeout(10, TimeUnit.SECONDS); // Disable timeouts for read mHttpClient.setReadTimeout(0, TimeUnit.MINUTES); Request request = new Request.Builder().url(url).build(); WebSocketCall call = WebSocketCall.create(mHttpClient, request); call.enqueue(this); }
protected void socket(String path, WebSocketListener listener) { Request.Builder req = new Request.Builder(); setWsPath(req, path); setKeys(req); setBody(req, Method.GET, null); WebSocketCall.create(ok, req.build()).enqueue(listener); }
private static Listener streamRequest(Request request, ApiClient client, io.kubernetes.client.util.WebSockets.SocketListener listener) { WebSocketCall webSocketCall = WebSocketCall.create(client.getHttpClient(), request); Listener listener1 = new Listener(listener, webSocketCall); webSocketCall.enqueue(listener1); return listener1; }
public Listener(io.kubernetes.client.util.WebSockets.SocketListener listener, WebSocketCall webSocketCall) { this.listener = listener; this.webSocketCall = webSocketCall; }
private void doOpen() { state = State.CONNECTING; OkHttpClient client; if (options.okHttpClientFactory != null) { client = options.okHttpClientFactory.createOkHttpClient(); } else { client = new OkHttpClient(); } if (options.sslContext != null) { final SSLSocketFactory factory = options.sslContext.getSocketFactory(); client.setSslSocketFactory(factory); } if (options.hostnameVerifier != null) { client.setHostnameVerifier(options.hostnameVerifier); } if (options.cookieHandler != null) { client.setCookieHandler(options.cookieHandler); } String url = uri.toString(); if (options.query != null) { url = url + "?" + QueryStringUtils.encode(options.query); } final Request.Builder builder = new Request.Builder().url(url); if (options.headers != null) { for (Map.Entry<String, String> entry : options.headers.entrySet()) { builder.addHeader(entry.getKey(), entry.getValue()); } } final Request request = builder.build(); final WebSocketCall webSocketCall = WebSocketCall.create(client, request); webSocketCall.enqueue(webSocketListener); client.getDispatcher().getExecutorService().shutdown(); }