Search in sources :

Example 46 with WebSocket

use of okhttp3.WebSocket in project Cobinhood.Java by jd-alexander.

the class CobinhoodSocket method doConnect.

private void doConnect() {
    if (webSocket != null) {
        if (eventStream.hasObservers()) {
            eventStream.accept(new Open());
        }
        return;
    }
    OkHttpClient okHttpClient = new OkHttpClient.Builder().build();
    okHttpClient.newWebSocket(request, webSocketListener());
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Open(api.cobinhood.websocket.models.Open)

Example 47 with WebSocket

use of okhttp3.WebSocket in project runelite by runelite.

the class WSClient method connect.

void connect() {
    Request request = new Request.Builder().url(RuneLiteAPI.getWsEndpoint()).build();
    webSocket = client.newWebSocket(request, this);
    Handshake handshake = new Handshake();
    handshake.setSession(session.getUuid());
    send(handshake);
}
Also used : Request(okhttp3.Request) Handshake(net.runelite.http.api.ws.messages.Handshake)

Example 48 with WebSocket

use of okhttp3.WebSocket in project drift-sdk-android by Driftt.

the class Socket method connect.

public void connect() throws IOException {
    LoggerHelper.logMessage(TAG, "connect");
    disconnect();
    // No support for ws:// or ws:// in okhttp. See https://github.com/square/okhttp/issues/1652
    final String httpUrl = this.endpointUri.replaceFirst("^ws:", "http:").replaceFirst("^wss:", "https:");
    final Request request = new Request.Builder().url(httpUrl).build();
    webSocket = httpClient.newWebSocket(request, wsListener);
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Request(okhttp3.Request) ByteString(okio.ByteString)

Example 49 with WebSocket

use of okhttp3.WebSocket in project okhttp by square.

the class RealWebSocketTest method smallMessagesNotCompressed.

@Test
public void smallMessagesNotCompressed() throws IOException {
    Headers headers = Headers.of("Sec-WebSocket-Extensions", "permessage-deflate");
    client.initWebSocket(random, 0, headers);
    server.initWebSocket(random, 0, headers);
    String message = TestUtil.repeat('a', (int) DEFAULT_MINIMUM_DEFLATE_SIZE - 1);
    server.webSocket.send(message);
    // Not compressed.
    assertThat(client.clientSourceBufferSize()).isGreaterThan(message.length());
    assertThat(client.processNextFrame()).isTrue();
    client.listener.assertTextMessage(message);
}
Also used : Headers(okhttp3.Headers) ByteString(okio.ByteString) Test(org.junit.jupiter.api.Test)

Example 50 with WebSocket

use of okhttp3.WebSocket in project okhttp by square.

the class WebSocketRecorder method onClosed.

@Override
public void onClosed(WebSocket webSocket, int code, String reason) {
    Platform.get().log("[WS " + name + "] onClosed " + code, Platform.INFO, null);
    WebSocketListener delegate = this.delegate;
    if (delegate != null) {
        this.delegate = null;
        delegate.onClosed(webSocket, code, reason);
    } else {
        events.add(new Closed(code, reason));
    }
}
Also used : WebSocketListener(okhttp3.WebSocketListener)

Aggregations

WebSocket (okhttp3.WebSocket)42 MockResponse (mockwebserver3.MockResponse)27 Test (org.junit.jupiter.api.Test)27 WebSocketListener (okhttp3.WebSocketListener)25 ByteString (okio.ByteString)20 Request (okhttp3.Request)16 Response (okhttp3.Response)9 OkHttpClient (okhttp3.OkHttpClient)8 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 Test (org.junit.Test)4 RecordedRequest (mockwebserver3.RecordedRequest)3 Single (io.reactivex.rxjava3.core.Single)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 DataInputStream (java.io.DataInputStream)2 InputStream (java.io.InputStream)2 StandardCharsets (java.nio.charset.StandardCharsets)2