@Override public void complete(boolean success) { session.getRemote().sendStringByFuture("{ \"command\": \"complete\", \"success\": " + success + " }"); } }
@Override public void progress(double value) { session.getRemote().sendStringByFuture("{ \"command\": \"compiling\", \"progress\": " + value + " }"); }
/** * Send an XML packet to the remote peer * * @param packet XML to be sent to client */ void deliver(String packet) { if (isWebSocketOpen()) { try { xmppSession.incrementServerPacketCount(); wsSession.getRemote().sendStringByFuture(packet); } catch (Exception e) { Log.error("Packet delivery failed; session: " + wsSession, e); Log.warn("Failed to deliver packet:\n" + packet ); } } else { Log.warn("Failed to deliver packet; socket is closed:\n" + packet); } }
@OnWebSocketMessage public void onMessage(String text) { send(t -> t.session.getRemote().sendStringByFuture(text)); }
/** * Sends a string via a particular {@link ColibriWebSocket} instance. * @param dst the {@link ColibriWebSocket} through which to send the message. * @param message the message to send. * @param errorMessage an error message to be logged in case of failure. */ private void sendMessage( ColibriWebSocket dst, String message, String errorMessage) { // We'll use the async version of sendString since this may be called // from multiple threads. It's just fire-and-forget though, so we // don't wait on the result dst.getRemote().sendStringByFuture(message); endpoint.getConference().getVideobridge().getStatistics() .totalColibriWebSocketMessagesSent.incrementAndGet(); }
private void sendPong() { getRemote().sendStringByFuture("pong"); }
public void sendMsg(String context, int sizeOfMessage) throws IOException, JsonParseException, InterruptedException, ExecutionException { byte[] payload = new byte[sizeOfMessage]; String message = getEncoder().encodeToString(payload); String timeStamp = "{\"payload\": \"" + message + "\",\"context\": \"" + context + "\"}"; String sampleMsg = new Gson().fromJson(timeStamp, JsonObject.class).toString(); if (this.session != null && this.session.isOpen() && this.session.getRemote() != null) { startTimeMap.put(context, System.nanoTime()); this.session.getRemote().sendStringByFuture(sampleMsg).get(); } else { log.error("Session is already closed"); } }
@OnWebSocketConnect public void onConnect(Session session) { System.out.printf("Got connect: %s%n", session); this.session = session; try { Future<Void> fut; fut = session.getRemote().sendStringByFuture("Hello"); fut.get(2, TimeUnit.SECONDS); fut = session.getRemote().sendStringByFuture("Thanks for the conversation."); fut.get(2, TimeUnit.SECONDS); session.close(StatusCode.NORMAL, "I'm done"); } catch (Throwable t) { t.printStackTrace(); } }
@Override public void send(String content) { Session session; synchronized (this) { session = _session; } try { if (session == null) { throw new IOException("Unconnected"); } // Blocking async sends for the client to allow concurrent sends. session.getRemote().sendStringByFuture(content).get(); } catch (Throwable x) { fail(x, "Exception"); } }
@Override public IWebSocketConnection sendMessage(String message) throws IOException { checkClosed(); session.getRemote().sendStringByFuture(message); return this; }
@Override protected void sendMessageString(String data) throws IOException { synchronized (this) { if (session == null) { LOG.warning("Websocket is not connected"); } else { session.getRemote().sendStringByFuture(data); } } } }
@Override public void onSocketOutboundText(String data) throws IOException { if (!transportStartedAtLeastOnce()) { LOG.debug("Waiting for WebSocket to be properly started..."); try { socketTransportStarted.await(); } catch (InterruptedException e) { LOG.warn("While waiting for WebSocket to be properly started, we got interrupted!! Should be okay, but you could see race conditions..."); } } LOG.trace("WS Proxy sending string of size {} out", data.length()); try { session.getRemote().sendStringByFuture(data).get(getDefaultSendTimeOut(), TimeUnit.SECONDS); } catch (Exception e) { throw IOExceptionSupport.create(e); } }
@Override public void onSocketOutboundText(String data) throws IOException { if (!transportStartedAtLeastOnce()) { LOG.debug("Waiting for WebSocket to be properly started..."); try { socketTransportStarted.await(); } catch (InterruptedException e) { LOG.warn("While waiting for WebSocket to be properly started, we got interrupted!! Should be okay, but you could see race conditions..."); } } LOG.trace("WS Proxy sending string of size {} out", data.length()); try { session.getRemote().sendStringByFuture(data).get(getDefaultSendTimeOut(), TimeUnit.SECONDS); } catch (Exception e) { throw IOExceptionSupport.create(e); } }
/** * Sends a message on the websocket. * * @param message The message to send. */ public void send(String message) { String filteredMessage = message.replace(client.getToken(), "hunter2"); if (getSession() != null && getSession().isOpen()) { Discord4J.LOGGER.trace(LogMarkers.WEBSOCKET_TRAFFIC, "Sending: " + filteredMessage); getSession().getRemote().sendStringByFuture(message); } else { Discord4J.LOGGER.warn(LogMarkers.WEBSOCKET, "Attempt to send message on closed session: {}", filteredMessage); } }
@Override public void sendToStomp(StompFrame command) throws IOException { try { //timeout after a period of time so we don't wait forever and hold the protocol lock session.getRemote().sendStringByFuture(getWireFormat().marshalToString(command)).get(getDefaultSendTimeOut(), TimeUnit.SECONDS); } catch (Exception e) { throw IOExceptionSupport.create(e); } }
/** * Sends a message on the websocket. * * @param message The message to send. */ public void send(String message) { if (getSession() != null && getSession().isOpen()) { getSession().getRemote().sendStringByFuture(message); } else { Discord4J.LOGGER.warn(LogMarkers.VOICE_WEBSOCKET, "Attempt to send message on closed session: {}", message); } }
@Override public void sendToStomp(StompFrame command) throws IOException { try { //timeout after a period of time so we don't wait forever and hold the protocol lock session.getRemote().sendStringByFuture(getWireFormat().marshalToString(command)).get(getDefaultSendTimeOut(), TimeUnit.SECONDS); } catch (Exception e) { throw IOExceptionSupport.create(e); } }
@Override public void sendToStomp(StompFrame command) throws IOException { try { //timeout after a period of time so we don't wait forever and hold the protocol lock session.getRemote().sendStringByFuture(getWireFormat().marshalToString(command)).get(getDefaultSendTimeOut(), TimeUnit.SECONDS); } catch (Exception e) { throw IOExceptionSupport.create(e); } }
Future<Void> sendMessage(DefaultWebsocket websocket, Object message) throws IOException { Future<Void> future = null; // in case there is web socket and socket connection is open - send message if (websocket != null && websocket.getSession().isOpen()) { log.trace("Sending to websocket {} -> {}", websocket.getConnectionKey(), message); if (message instanceof String) { future = websocket.getSession().getRemote().sendStringByFuture((String) message); } else if (message instanceof byte[]) { ByteBuffer buf = ByteBuffer.wrap((byte[]) message); future = websocket.getSession().getRemote().sendBytesByFuture(buf); } } return future; }
public Future<Void> sendMessage(String message) { if (logger.isTraceEnabled()) { logger.entry(message); } final Future<Void> result = session.getRemote().sendStringByFuture(message); if (logger.isTraceEnabled()) { logger.exit(result); } return result; }