@Override public void send(ByteBuffer data) throws IOException { session.getRemote().sendBytes(data); }
@Override protected void sendBinaryMessage(BinaryMessage message) throws IOException { getRemoteEndpoint().sendBytes(message.getPayload()); }
@Override public void sendBinary(final ByteBuffer data) throws IOException { session.getRemote().sendBytes(data); }
@Override public TransportConnection send( byte[] rawBytes ) throws IOException { // The WS client *mutates* the buffer we give it, so we need to copy it here to allow the caller to retain // ownership ByteBuffer wrap = ByteBuffer.wrap( Arrays.copyOf( rawBytes, rawBytes.length ) ); server.sendBytes( wrap ); return this; }
@Override public void sendBytes(final ByteBuffer data, final SuccessCallback success, final OnError err) { requireNonNull(data, NO_DATA_TO_SEND); RemoteEndpoint remote = session.getRemote(); remote.sendBytes(data, callback(log, success, err)); }
@Override public void onWebSocketBinary(byte[] payload, int offset, int len) { if (isNotConnected()) { return; } try { LOGGER.debug("Received binary frame of size {}: {}", len, new String(payload, offset, len, UTF_8)); getRemote().sendBytes(ByteBuffer.wrap(payload, offset, len)); } catch (IOException e) { e.printStackTrace(); } }
@OnWebSocketConnect public void onConnect(Session session) throws IOException { System.out.printf("Got connect: %s%n", session); LOG.info("Got connect: %s%n", session); // Trivial MQTT Connect message // assertEquals(12, out.readByte()); //remaining length // verifyString("MQIsdp", out); // assertEquals(0x03, out.readByte()); //protocol version // assertEquals(0x32, out.readByte()); //flags // assertEquals(2, out.readByte()); //keepAliveTimer msb // assertEquals(0, out.readByte()); //keepAliveTimer lsb ByteBuffer msg = ByteBuffer.wrap(new byte[]{0x10, // message type 0x0C, // remaining lenght 12 bytes 'M', 'Q', 'I', 's', 'd', 'p', 0x03, // protocol version 0x32, // flags 0x02, 0x00// keepAlive Timer, 2 seconds }); // try { session.getRemote().sendBytes(msg); this.connectSentLatch.countDown(); session.close(StatusCode.NORMAL, "I'm done"); // } catch (IOException t) { // LOG.error(null, t); // } }
@Override protected boolean sendMessage(WebSocketMessage message) throws IOException { ByteBuffer buffer = message.getPayload().asByteBuffer(); if (WebSocketMessage.Type.TEXT.equals(message.getType())) { getSendProcessor().setReadyToSend(false); String text = new String(buffer.array(), StandardCharsets.UTF_8); getDelegate().getRemote().sendString(text, new SendProcessorCallback()); } else if (WebSocketMessage.Type.BINARY.equals(message.getType())) { getSendProcessor().setReadyToSend(false); getDelegate().getRemote().sendBytes(buffer, new SendProcessorCallback()); } else if (WebSocketMessage.Type.PING.equals(message.getType())) { getDelegate().getRemote().sendPing(buffer); } else if (WebSocketMessage.Type.PONG.equals(message.getType())) { getDelegate().getRemote().sendPong(buffer); } else { throw new IllegalArgumentException("Unexpected message type: " + message.getType()); } return true; }
@Override public WebSocketConnection sendMessage(byte[] message) throws IOException { checkClosed(); ByteBuffer buffer = ByteBuffer.wrap(message, 0, message.length); session.getRemote().sendBytes(buffer); return this; }
/** * Send a binary message. * <p> * Basic usage, results in a blocking write. */ public void write(byte[] data, int offset, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(data,offset,length); remote.sendBytes(buf); }
/** * Send a binary message. * <p> * Basic usage, results in a blocking write. */ public void write(byte[] data, int offset, int length) throws IOException { ByteBuffer buf = ByteBuffer.wrap(data,offset,length); remote.sendBytes(buf); }
@Override public void sendBytes(byte[] data) throws IOException { session.getRemote().sendBytes(ByteBuffer.wrap(data)); } }
@Override public void sendBytes(byte[] data) throws IOException { session.getRemote().sendBytes(ByteBuffer.wrap(data)); } }
@Override public void send(String message) { try { session.getRemote().sendBytes(ByteBuffer.wrap(message.getBytes(Charsets.UTF_8))); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void onMessage(Session session, byte[] bytes) { try { session.getRemote().sendBytes(ByteBuffer.wrap(bytes)); } catch (IOException e) { e.printStackTrace(); } }
private void encodeAndSend(List<AbstractMessage> send) throws IOException { if (send.size() > 0) { logger.finest(String.format("Sending %d messages", send.size())); ByteBuffer toSend = msgmap.encode(send); logger.finest(String.format("Sending buffer len %d", toSend.capacity())); wsSession.getRemote().sendBytes(toSend); send.clear(); } } public void stop() {
@Override protected void onMessage(byte[] messageData) throws IOException { try { if (this.session == null) return; this.session.getRemote().sendBytes(ByteBuffer.wrap(messageData)); } catch (IOException ex) { log.error("Could not send stdio to " + session.getRemote().toString() + ": " + ex.getMessage()); } } }
@Override public void sendBytes(final ByteBuffer data, final SuccessCallback success, final OnError err) { requireNonNull(data, NO_DATA_TO_SEND); RemoteEndpoint remote = session.getRemote(); remote.sendBytes(data, callback(log, success, err)); }
@Override public Connection send( byte[] rawBytes ) throws Exception { // The WS client *mutates* the buffer we give it, so we need to copy it here to allow the caller to retain // ownership ByteBuffer wrap = ByteBuffer.wrap( Arrays.copyOf( rawBytes, rawBytes.length ) ); server.sendBytes( wrap ); return this; }
@Override public void flush() throws IOException { final ByteBuffer byteBuffer; synchronized (this) { byteBuffer = ByteBuffer.wrap(toByteArray()); reset(); } // Asynchronous call getRemote().sendBytes(byteBuffer); getRemote().flush(); } };