本文整理了Java中org.asynchttpclient.ws.WebSocket.sendTextFrame()
方法的一些代码示例,展示了WebSocket.sendTextFrame()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocket.sendTextFrame()
方法的具体详情如下:
包路径:org.asynchttpclient.ws.WebSocket
类名称:WebSocket
方法名:sendTextFrame
[英]Allows sending a text frame with fragmentation or extension bits. When using fragmentation, the next fragments must be sent with sendContinuationFrame.
[中]允许发送带有碎片或扩展位的文本帧。使用碎片时,下一个碎片必须与sendContinuationFrame一起发送。
代码示例来源:origin: AsyncHttpClient/async-http-client
@Override
public void onOpen(WebSocket websocket) {
websocket.sendTextFrame("ECHO");
websocket.sendTextFrame("ECHO");
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(expectedExceptions = ExecutionException.class)
public void streamTextExpectFailure() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
CountDownLatch closeLatch = new CountDownLatch(1);
WebSocket websocket = getWebSocket(c, closeLatch);
websocket.sendCloseFrame();
closeLatch.await(1, TimeUnit.SECONDS);
websocket.sendTextFrame("STREAM", true, 0).get(1, TimeUnit.SECONDS);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(timeOut = 60000, expectedExceptions = ExecutionException.class)
public void sendTextMessageExpectFailure() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
CountDownLatch closeLatch = new CountDownLatch(1);
WebSocket websocket = getWebSocket(c, closeLatch);
websocket.sendCloseFrame();
closeLatch.await(1, TimeUnit.SECONDS);
websocket.sendTextFrame("TEXT").get(10, TimeUnit.SECONDS);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(timeOut = 60000)
public void sendTextMessage() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
getWebSocket(c).sendTextFrame("TEXT").get(10, TimeUnit.SECONDS);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test
public void streamText() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
getWebSocket(c).sendTextFrame("STREAM", true, 0).get(1, TimeUnit.SECONDS);
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
websocket.sendTextFrame("ECHO");
textLatch.await();
websocket.sendTextFrame("CLOSE");
closeLatch.await();
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test(timeOut = 60000)
public void echoText() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<String> text = new AtomicReference<>("");
WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() {
@Override
public void onTextFrame(String payload, boolean finalFragment, int rsv) {
text.set(payload);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket, int code, String reason) {
latch.countDown();
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
latch.countDown();
}
}).build()).get();
websocket.sendTextFrame("ECHO");
latch.await();
assertEquals(text.get(), "ECHO");
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test
public void echoFragments() throws Exception {
try (AsyncHttpClient c = asyncHttpClient()) {
final CountDownLatch latch = new CountDownLatch(1);
final AtomicReference<String> text = new AtomicReference<>("");
WebSocket websocket = c.prepareGet(getTargetUrl()).execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(new WebSocketListener() {
@Override
public void onTextFrame(String payload, boolean finalFragment, int rsv) {
text.set(payload);
latch.countDown();
}
@Override
public void onOpen(WebSocket websocket) {
}
@Override
public void onClose(WebSocket websocket, int code, String reason) {
latch.countDown();
}
@Override
public void onError(Throwable t) {
t.printStackTrace();
latch.countDown();
}
}).build()).get();
websocket.sendTextFrame("ECHO", false, 0);
websocket.sendContinuationFrame("ECHO", true, 0);
latch.await();
assertEquals(text.get(), "ECHOECHO");
}
}
代码示例来源:origin: AsyncHttpClient/async-http-client
websocket.sendTextFrame("ECHO");
代码示例来源:origin: AsyncHttpClient/async-http-client
websocket.sendTextFrame("ECHO");
代码示例来源:origin: allbegray/slack-api
/**
* This method sends message to slack using webSocket client
* @param message
*/
public void sendMessage(String message){
webSocket.sendTextFrame(message);
}
代码示例来源:origin: org.apache.camel/camel-ahc-ws
private void sendMessage(WebSocket webSocket, String msg, boolean streaming) {
if (streaming) {
int p = 0;
while (p < msg.length()) {
if (msg.length() - p < streamBufferSize) {
webSocket.sendTextFrame(msg.substring(p), true, 0);
p = msg.length();
} else {
webSocket.sendTextFrame(msg.substring(p, streamBufferSize), false, 0);
p += streamBufferSize;
}
}
} else {
webSocket.sendTextFrame(msg);
}
}
代码示例来源:origin: allbegray/slack-api
private void ping() {
ObjectNode pingMessage = mapper.createObjectNode();
pingMessage.put("id", ++socketId);
pingMessage.put("type", "ping");
String pingJson = pingMessage.toString();
webSocket.sendTextFrame(pingJson);
logger.debug("ping : " + pingJson);
}
代码示例来源:origin: org.apache.camel/camel-ahc-ws
@Override
public void process(Exchange exchange) throws Exception {
Message in = exchange.getIn();
Object message = in.getBody();
if (message != null) {
log.debug("Sending out {}", message);
if (message instanceof String) {
sendMessage(getWebSocket(), (String)message, getEndpoint().isUseStreaming());
} else if (message instanceof byte[]) {
sendMessage(getWebSocket(), (byte[])message, getEndpoint().isUseStreaming());
} else if (message instanceof InputStream) {
sendStreamMessage(getWebSocket(), (InputStream)message);
} else {
//TODO provide other binding option, for now use the converted string
getWebSocket().sendTextFrame(in.getMandatoryBody(String.class));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!