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


Java WebSocketCall.create方法代码示例

本文整理汇总了Java中okhttp3.ws.WebSocketCall.create方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocketCall.create方法的具体用法?Java WebSocketCall.create怎么用?Java WebSocketCall.create使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在okhttp3.ws.WebSocketCall的用法示例。


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

示例1: createWebSocketCall

import okhttp3.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-agent,代码行数:26,代码来源:BaseHttpClientGenerator.java

示例2: sendCommand

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
private static CliWebSocketListener sendCommand(Config config) throws Exception {

        OkHttpClient httpClient = new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(5, TimeUnit.MINUTES).build();

        Request request = new Request.Builder()
                .url(config.serverUrl)
                .addHeader("Authorization", Credentials.basic(config.username, config.password))
                .addHeader("Accept", "application/json")
                .build();

        WebSocketCall wsc = WebSocketCall.create(httpClient, request);
        CliWebSocketListener listener = new CliWebSocketListener(httpClient, wsc, config);
        return listener;
    }
 
开发者ID:hawkular,项目名称:hawkular-agent,代码行数:17,代码来源:CommandCli.java

示例3: connect

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
@Override
public synchronized void connect(ConnCallback cb) {
    if (cb == null) {
        throw new IllegalArgumentException("callback cannot be null");
    }
    State s = state.get();
    if (s == State.CONNECTED || s == State.CONNECTING) {
        return;
    }

    // enqueue this listener implementation to initiate the WebSocket connection
    state.set(State.CONNECTING);
    connCallback = cb;
    wsConnectRequest = WebSocketCall.create(client, new Request.Builder().url(ws_url).build());
    wsConnectRequest.enqueue(this);
}
 
开发者ID:nbusy,项目名称:nbusy-android,代码行数:17,代码来源:ConnImpl.java

示例4: connect

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
public void connect() {
  if (mClosed) {
    throw new IllegalStateException("Can't connect closed client");
  }
  OkHttpClient httpClient = new OkHttpClient.Builder()
      .connectTimeout(10, TimeUnit.SECONDS)
      .writeTimeout(10, TimeUnit.SECONDS)
      .readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read
      .build();

  Request request = new Request.Builder().url(mUrl).build();
  WebSocketCall call = WebSocketCall.create(httpClient, request);
  call.enqueue(this);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:15,代码来源:InspectorPackagerConnection.java

示例5: connect

import okhttp3.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.Builder()
    .connectTimeout(10, TimeUnit.SECONDS)
    .writeTimeout(10, TimeUnit.SECONDS)
    .readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read
    .build();

  Request request = new Request.Builder().url(url).build();
  WebSocketCall call = WebSocketCall.create(mHttpClient, request);
  call.enqueue(this);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:16,代码来源:JSDebuggerWebSocketClient.java

示例6: connect

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
public void connect() {
  if (mClosed) {
    throw new IllegalStateException("Can't connect closed client");
  }

  OkHttpClient httpClient = new OkHttpClient.Builder()
    .connectTimeout(10, TimeUnit.SECONDS)
    .writeTimeout(10, TimeUnit.SECONDS)
    .readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read
    .build();

  Request request = new Request.Builder().url(mUrl).build();
  WebSocketCall call = WebSocketCall.create(httpClient, request);
  call.enqueue(this);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:16,代码来源:ReconnectingWebSocket.java

示例7: connect

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
public final void connect() throws IOException {
    if (this.status != ConnectionStatus.CONNECTING) {
        this.status = ConnectionStatus.CONNECTING;
        WebSocketCall ws = WebSocketCall.create(this.client, this.request);
        ws.enqueue(this);
    }
}
 
开发者ID:artikcloud,项目名称:artikcloud-java,代码行数:8,代码来源:WebSocketProxy.java

示例8: connect

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
public void connect() {
    logInfo("connect() while environment is " +
            "(state="+mState+", address="+address+", " +
            "SendMsgQueueSize="+mSendMessageThread.mMessageQueue.size()+")");

    if (mState != State.Offline) return;

    if (TextUtils.isEmpty(address)) {
        throw new NullPointerException("address is empty!");
    }

    if (mReconnectSignalHandler == null) {
        HandlerThread handlerThread = new HandlerThread("ReconnectSignalHandlerThread");
        handlerThread.start();
        mReconnectSignalHandler = new ReconnectSignalHandler(this, handlerThread);
    }

    setAndNotifyStateChanged(State.Connecting);

    Request request = new Request.Builder().url(getAddress())
            .build();
    mWebSocketCall = WebSocketCall.create(mNetworkClient.getOkHttpClient(),
            request);
    mWSListener = new WSListener();
    mWebSocketCall.enqueue(mWSListener);

    if (mSendMessageThread.getState() != Thread.State.NEW) {
        mSendMessageThread = mSendMessageThread.clone();
    }
}
 
开发者ID:yangxlei,项目名称:bjnetwork,代码行数:31,代码来源:BJWebSocketClient.java

示例9: connect

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
public void connect() {
  if (mClosed) {
    throw new IllegalStateException("Can't connect closed client");
  }
  OkHttpClient  httpClient = new OkHttpClient.Builder()
      .connectTimeout(10, TimeUnit.SECONDS)
      .writeTimeout(10, TimeUnit.SECONDS)
      .readTimeout(0, TimeUnit.MINUTES) // Disable timeouts for read
      .build();

  Request request = new Request.Builder().url(mUrl).build();
  WebSocketCall call = WebSocketCall.create(httpClient, request);
  call.enqueue(this);
}
 
开发者ID:Right-Men,项目名称:Ironman,代码行数:15,代码来源:JSPackagerWebSocketClient.java

示例10: OkHttpWebSocketConnection

import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
public OkHttpWebSocketConnection(Request request, OkHttpClient client) {
  this.call = WebSocketCall.create(client, request);
  start();
}
 
开发者ID:csync,项目名称:csync-android,代码行数:5,代码来源:OkHttpWebSocketConnection.java


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