本文整理汇总了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();
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
}
示例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();
}
}
示例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);
}
示例13: OkHttpWebSocketConnection
import okhttp3.ws.WebSocketCall; //导入依赖的package包/类
public OkHttpWebSocketConnection(Request request, OkHttpClient client) {
this.call = WebSocketCall.create(client, request);
start();
}
示例14: FayeImpl
import okhttp3.ws.WebSocketCall; //导入依赖的package包/类
FayeImpl(WebSocketCall call, long pingInterval) {
this.call = call;
this.pingInterval = pingInterval;
state = UNCONNECTED;
advice = new Advice();
}
示例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);
}