gpt4 book ai didi

org.atmosphere.websocket.WebSocket.write()方法的使用及代码示例

转载 作者:知者 更新时间:2024-03-27 13:05:05 26 4
gpt4 key购买 nike

本文整理了Java中org.atmosphere.websocket.WebSocket.write()方法的一些代码示例,展示了WebSocket.write()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocket.write()方法的具体详情如下:
包路径:org.atmosphere.websocket.WebSocket
类名称:WebSocket
方法名:write

WebSocket.write介绍

[英]Use the underlying container's websocket to write the byte.
[中]使用底层容器的websocket写入字节。

代码示例

代码示例来源:origin: Atmosphere/atmosphere

/**
 * Use the underlying container's websocket to write the byte.
 *
 * @param b      a websocket byte message
 * @return this
 * @throws IOException
 */
public WebSocket write(byte[] b) throws IOException {
  return write(b, 0, b.length);
}

代码示例来源:origin: Atmosphere/atmosphere

@Override
public WebSocket write(AtmosphereResponse r, byte[] data) throws IOException {
  if (data == null) {
    logger.error("Cannot write null value for {}", resource());
    return this;
  }
  return write(r, data, 0, data.length);
}

代码示例来源:origin: Atmosphere/atmosphere

write(b, 0, b.length);
write(data);

代码示例来源:origin: Atmosphere/atmosphere

@Override
public WebSocket write(AtmosphereResponse r, String data) throws IOException {
  firstWrite.set(true);
  if (data == null) {
    logger.error("Cannot write null value for {}", resource());
    return this;
  }
  if (!isOpen()) throw new IOException("Connection remotely closed for " + uuid);
  logger.trace("WebSocket.write() {}", data);
  boolean transform = !filters.isEmpty() && r.getStatus() < 400;
  if (binaryWrite) {
    byte[] b = data.getBytes(resource().getResponse().getCharacterEncoding());
    if (transform) {
      b = transform(r, b, 0, b.length);
    }
    if (b != null) {
      write(b, 0, b.length);
    }
  } else {
    if (transform) {
      byte[] b = data.getBytes(resource().getResponse().getCharacterEncoding());
      data = new String(transform(r, b, 0, b.length), r.getCharacterEncoding());
    }
    if (data != null) {
      write(data);
    }
  }
  lastWrite = System.currentTimeMillis();
  return this;
}

代码示例来源:origin: org.apache.camel/camel-atmosphere-websocket

@Override
  public void run() {
    try {
      if (message instanceof String) {
        websocket.write((String) message);
      } else if (message instanceof byte[]) {
        websocket.write((byte[]) message, 0, ((byte[]) message).length);
      } else {
        // this should not happen unless one of the supported types is missing above.
        LOG.warn("unexpected message type {}", message.getClass());
      }
    } catch (Exception e) {
      LOG.error("Error when writing to websocket", e);
    }
  }
});

代码示例来源:origin: motown-io/motown

private void writeToSocket(String message) throws IOException {
  LOG.info("Writing to charging station [{}]: {}", chargingStationId.getId(), message);
  webSocket.write(message);
}

代码示例来源:origin: Atmosphere/atmosphere-extensions

@Override
public void sendMessage(String message) throws SocketIOException {
  logger.trace("calling from " + this.getClass().getName() + " : " + "sendMessage(string) = " + message);
  if (webSocket != null) {
    try {
      webSocket.write(message);
      logger.trace("WRITE SUCCESS : calling from " + this.getClass().getName() + " : " + "sendMessage(string) = " + message);
    } catch (IOException e) {
      throw new SocketIOException(e);
    }
  } else {
    logger.warn("WebSOCKET NULL");
  }
}

代码示例来源:origin: com.vaadin.external.atmosphere/atmosphere-socketio

@Override
public void sendMessage(String message) throws SocketIOException {
  logger.trace("calling from " + this.getClass().getName() + " : " + "sendMessage(string) = " + message);
  if (webSocket != null) {
    try {
      webSocket.write(message);
      logger.trace("WRITE SUCCESS : calling from " + this.getClass().getName() + " : " + "sendMessage(string) = " + message);
    } catch (IOException e) {
      e.printStackTrace();
    }
  } else {
    logger.warn("WebSOCKET NULL");
  }
}

代码示例来源:origin: Atmosphere/atmosphere-extensions

@Override
public void onConnect(WebSocketEvent event) {
  logger.trace("calling from " + this.getClass().getName() + " : " + "onConnect");
  sessionWrapper.setWebSocket(event.webSocket());
  try {
    event.webSocket().write(new SocketIOPacketImpl(PacketType.CONNECT).toString());
  } catch (IOException e) {
    e.printStackTrace();
    sessionWrapper.getSession().onShutdown();
  }
  try {
    sessionWrapper.getSession().setAtmosphereResourceImpl((AtmosphereResourceImpl) event.webSocket().resource());
    sessionWrapper.getSession().onConnect(sessionWrapper.getSession().getAtmosphereResourceImpl(), sessionWrapper);
    sessionWrapper.initiated(true);
  } catch (Exception e) {
    logger.error(e.getMessage(),e);
    sessionWrapper.getSession().onShutdown();
  }
}

代码示例来源:origin: com.wordnik/swaggersocket

webSocket.write(resource.getResponse(), mapper.writeValueAsBytes(statusMessage));
webSocket.webSocketResponseFilter(serializer);
  StatusMessage statusMessage = new StatusMessage.Builder().status(new StatusMessage.Status(503, "Not Allowed"))
      .identity(identity).build();
  webSocket.write(resource.getResponse(), mapper.writeValueAsBytes(statusMessage));
  return null;

代码示例来源:origin: com.vaadin.external.atmosphere/atmosphere-socketio

@Override
public void onConnect(WebSocketEvent event) {
  logger.trace("calling from " + this.getClass().getName() + " : " + "onConnect");
  sessionWrapper.setWebSocket(event.webSocket());
  try {
    event.webSocket().write(new SocketIOPacketImpl(PacketType.CONNECT).toString());
  } catch (IOException e) {
    e.printStackTrace();
    sessionWrapper.getSession().onShutdown();
  }
  try {
    sessionWrapper.getSession().setAtmosphereResourceImpl((AtmosphereResourceImpl) event.webSocket().resource());
    sessionWrapper.getSession().onConnect(sessionWrapper.getSession().getAtmosphereResourceImpl(), sessionWrapper);
    sessionWrapper.initiated(true);
  } catch (Exception e) {
    e.printStackTrace();
    sessionWrapper.getSession().onShutdown();
  }
}

代码示例来源:origin: com.wordnik/swaggersocket

/**
 * {@inheritDoc}
 */
@Override
public void onError(WebSocket webSocket, WebSocketProcessor.WebSocketException t) {
  if (t.response() != null) {
    Request swaggerSocketRequest =
        Request.class.cast(t.response().request().getAttribute(String.valueOf(t.response().request().hashCode())));
    if (swaggerSocketRequest == null) {
      logger.debug("Handshake mapping (could be expected) {} : {}", t.response().getStatus(), t.response().getStatusMessage());
      return;
    }
    logger.debug("Unexpected status code {} : {}", t.response().getStatus(), t.response().getStatusMessage());
    StatusMessage statusMessage = new StatusMessage.Builder()
        .status(new StatusMessage.Status(t.response().getStatus(),
            t.response().getStatusMessage()))
        .identity(swaggerSocketRequest.getUuid()).build();
    try {
      byte[] b = mapper.writeValueAsBytes(statusMessage);
      webSocket.write(t.response(), b, 0, b.length);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com