本文整理汇总了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);
}
示例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);
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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();
}