use of org.java_websocket.client.WebSocketClient in project intellij-community by JetBrains.
the class IpnbConnection method initializeClients.
protected void initializeClients() throws URISyntaxException {
final Draft draft = new Draft17WithOrigin();
myShellClient = new WebSocketClient(getShellURI(), draft, myHeaders, 0) {
@Override
public void onOpen(@NotNull ServerHandshake handshakeData) {
final Message message = createMessage("connect_request", UUID.randomUUID().toString(), null, null);
send(new Gson().toJson(message));
myIsShellOpen = true;
notifyOpen();
}
@Override
public void onMessage(@NotNull String message) {
}
@Override
public void onClose(int code, @NotNull String reason, boolean remote) {
}
@Override
public void onError(@NotNull Exception e) {
}
};
myShellThread = new Thread(myShellClient, "IPNB shell client");
myShellThread.start();
myIOPubClient = new IpnbWebSocketClient(getIOPubURI(), draft);
myIOPubThread = new Thread(myIOPubClient, "IPNB pub client");
myIOPubThread.start();
}
use of org.java_websocket.client.WebSocketClient in project ChatExchange by HueToYou.
the class WebSocketBackend method createWebSocket.
/**
* Creates the WebSocket using the provided URI
* @param uri WebSocket URI
*/
private void createWebSocket(URI uri) {
Map<String, String> headers = new HashMap<>();
headers.put("Cookie", mRequestFactory.cookies());
headers.put("Origin", "https://chat.stackexchange.com");
mWebSocketClient = new WebSocketClient(uri, new Draft_17(), headers, 0) {
@Override
public void onOpen(ServerHandshake serverHandshake) {
Log.i(TAG, "WebSocket connection opened");
}
@Override
public void onMessage(String s) {
for (Event event : mGson.fromJson(s, WsMessage.class).events) {
mBroadcaster.broadcastEvent(event);
}
}
@Override
public void onClose(int i, String s, boolean b) {
// TODO
}
@Override
public void onError(Exception e) {
Log.e(TAG, e.getMessage());
// TODO
}
};
}
Aggregations