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


Java WebSocketCall类代码示例

本文整理汇总了Java中com.squareup.okhttp.ws.WebSocketCall的典型用法代码示例。如果您正苦于以下问题:Java WebSocketCall类的具体用法?Java WebSocketCall怎么用?Java WebSocketCall使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: connect

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
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);
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:17,代码来源:WXWebSocketManager.java

示例2: connect

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
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);
    }
}
 
开发者ID:Laisly,项目名称:weex,代码行数:18,代码来源:DebugSocketClient.java

示例3: openConnection

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
/**
 * 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);
}
 
开发者ID:lukamarin,项目名称:Rocket.Chat-android,代码行数:28,代码来源:Meteor.java

示例4: createWebSocketCall

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
/**
 * 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;
}
 
开发者ID:hawkular,项目名称:hawkular-android-client,代码行数:26,代码来源:WebSocketClientGenerator.java

示例5: connect

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
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;
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:8,代码来源:HotRefreshManager.java

示例6: connect

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
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);
}
 
开发者ID:john1jan,项目名称:ReactNativeSignatureExample,代码行数:16,代码来源:JSDebuggerWebSocketClient.java

示例7: socket

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
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);
}
 
开发者ID:Appstax,项目名称:appstax-java,代码行数:8,代码来源:AxClient.java

示例8: streamRequest

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
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;
}
 
开发者ID:membrane,项目名称:kubernetes-client,代码行数:7,代码来源:WebSockets.java

示例9: Listener

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
public Listener(io.kubernetes.client.util.WebSockets.SocketListener listener, WebSocketCall webSocketCall) {
    this.listener = listener;
    this.webSocketCall = webSocketCall;
}
 
开发者ID:membrane,项目名称:kubernetes-client,代码行数:5,代码来源:WebSockets.java

示例10: doOpen

import com.squareup.okhttp.ws.WebSocketCall; //导入依赖的package包/类
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();
}
 
开发者ID:hosopy,项目名称:actioncable-client-java,代码行数:44,代码来源:Connection.java


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