本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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 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);
}
}
示例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();
}
}
示例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);
}
示例10: OkHttpWebSocketConnection
import okhttp3.ws.WebSocketCall; //导入方法依赖的package包/类
public OkHttpWebSocketConnection(Request request, OkHttpClient client) {
this.call = WebSocketCall.create(client, request);
start();
}