Created
May 3, 2017 07:21
-
-
Save jumperchen/6f8410b871a6d3746fe1967340d7a1a1 to your computer and use it in GitHub Desktop.
onClosing : 1001 reason
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.concurrent.TimeUnit; | |
import okio.ByteString; | |
public class TestOKHttp { | |
private static OkHttpClient client; | |
private static WebSocket ws; | |
private static boolean success = false; | |
public static void main(String[] args) throws Exception { | |
client = new OkHttpClient.Builder().pingInterval(30, TimeUnit.SECONDS).build(); | |
Request wsRequest = new Request.Builder() | |
.url("ws://echo.websocket.org") | |
.build(); | |
ws = client.newWebSocket(wsRequest, new WebSocketListener() { | |
@Override | |
public void onOpen(WebSocket webSocket, Response response) { | |
System.out.println("onOpen"); | |
for (int i = 0; i < 1000000; i++) | |
webSocket.send("Long.........words count: " + i); | |
} | |
@Override | |
public void onMessage(WebSocket webSocket, String text) { | |
System.out.println("onMessage : " + text); | |
success = true; | |
} | |
@Override | |
public void onMessage(WebSocket webSocket, ByteString bytes) { | |
System.out.println("onMessage binary "); | |
} | |
@Override | |
public void onClosing(WebSocket webSocket, int code, String reason) { | |
System.out.println("onClosing : " + code + " " + reason); | |
} | |
@Override | |
public void onClosed(WebSocket webSocket, int code, String reason) { | |
System.out.println("onClosed" + code + " " + reason); | |
} | |
@Override | |
public void onFailure(WebSocket webSocket, Throwable t, Response response) { | |
System.out.println("onFailure : " + t.getMessage()); | |
t.printStackTrace(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment