com.squareup.okhttp.ws.WebSocketCall Java Examples

The following examples show how to use com.squareup.okhttp.ws.WebSocketCall. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WXWebSocketManager.java    From weex with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #2
Source File: WebSocketClientGenerator.java    From hawkular-android-client with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #3
Source File: HotRefreshManager.java    From incubator-weex-playground with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #4
Source File: HotRefreshManager.java    From analyzer-of-android-for-Apache-Weex with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #5
Source File: HotRefreshManager.java    From weex with Apache License 2.0 5 votes vote down vote up
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;
}