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


Java WebSocketCall类代码示例

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


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

示例1: connect

import okhttp3.ws.WebSocketCall; //导入依赖的package包/类
public void connect() {
    Timber.v("connect()");

    Single.create(new Single.OnSubscribe<Void>() {
        @Override
        public void call(final SingleSubscriber<? super Void> singleSubscriber) {
            if (connectionState == ConnectionState.Disconnected) {
                Timber.d("Attempting to connect to web socket.");

                Request request = new Request.Builder()
                        .url(sessionManager.getServer() + "/api/v3/users/websocket")
                        .header(HttpHeaders.AUTHORIZATION,
                                HttpHeaders.buildAuthorizationHeader(sessionManager.getToken()))
                        .build();

                WebSocketCall.create(httpClient, request).enqueue(WebSocketManager.this);
                setConnectionState(connectionState = ConnectionState.Connecting);
            }

            singleSubscriber.onSuccess(null);
        }
    })
            .subscribeOn(AndroidSchedulers.from(thread.getLooper()))
            .subscribe();
}
 
开发者ID:grundleborg,项目名称:matterdroid,代码行数:26,代码来源:WebSocketManager.java

示例2: TestWebSocketClient

import okhttp3.ws.WebSocketCall; //导入依赖的package包/类
private TestWebSocketClient(Request request, TestListener testListener, int connectTimeoutSeconds,
        int readTimeoutSeconds) {
    super();
    if (request == null) {
        throw new IllegalStateException(
                "Cannot build a [" + TestWebSocketClient.class.getName() + "] with a null request");
    }
    this.listener = testListener;
    OkHttpClient c = new OkHttpClient.Builder()
            .connectTimeout(connectTimeoutSeconds, TimeUnit.SECONDS)
            .readTimeout(readTimeoutSeconds, TimeUnit.SECONDS)
            .build();
    this.client = c;

    WebSocketCall.create(client, request).enqueue(testListener);
}
 
开发者ID:hawkular,项目名称:hawkular-commons,代码行数:17,代码来源:TestWebSocketClient.java

示例3: 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

示例4: 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

示例5: 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

示例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,代码行数:15,代码来源:InspectorPackagerConnection.java

示例7: 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

示例8: 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

示例9: run

import okhttp3.ws.WebSocketCall; //导入依赖的package包/类
private void run() throws IOException {
  OkHttpClient client = new OkHttpClient();

  Request request = new Request.Builder()
      .url("ws://echo.websocket.org")
      .build();
  WebSocketCall.create(client, request).enqueue(this);

  // Trigger shutdown of the dispatcher's executor so this process can exit cleanly.
  client.dispatcher().executorService().shutdown();
}
 
开发者ID:lizhangqu,项目名称:PriorityOkHttp,代码行数:12,代码来源:WebSocketEcho.java

示例10: 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

示例11: 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

示例12: 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

示例13: 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

示例14: FayeImpl

import okhttp3.ws.WebSocketCall; //导入依赖的package包/类
FayeImpl(WebSocketCall call, long pingInterval) {
    this.call = call;
    this.pingInterval = pingInterval;
    state = UNCONNECTED;
    advice = new Advice();
}
 
开发者ID:mariotaku,项目名称:OkFaye,代码行数:7,代码来源:FayeImpl.java

示例15: create

import okhttp3.ws.WebSocketCall; //导入依赖的package包/类
/**
 * Create a Faye client from WebSocket call
 */
public static Faye create(OkHttpClient client, WebSocketCall call) {
    return new FayeImpl(call, client.readTimeoutMillis() / 2);
}
 
开发者ID:mariotaku,项目名称:OkFaye,代码行数:7,代码来源:Faye.java


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