本文整理了Java中io.advantageous.qbit.http.websocket.WebSocket.openAndWait()
方法的一些代码示例,展示了WebSocket.openAndWait()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebSocket.openAndWait()
方法的具体详情如下:
包路径:io.advantageous.qbit.http.websocket.WebSocket
类名称:WebSocket
方法名:openAndWait
暂无
代码示例来源:origin: advantageous/qbit
@Test
public void testBinary() throws Exception {
final int port = PortUtils.findOpenPortStartAt(4001);
final HttpServer httpServer = HttpServerBuilder.httpServerBuilder().setPort(port).build();
final AtomicReference<Object> bodyRef = new AtomicReference<>();
final AtomicReference<byte[]> messageRef = new AtomicReference<>();
final CountDownLatch countDownLatch = new CountDownLatch(2);
httpServer.setWebSocketMessageConsumer(webSocketMessage -> {
bodyRef.set(webSocketMessage.body());
webSocketMessage.getSender().sendBytes("world".getBytes());
countDownLatch.countDown();
});
httpServer.startServerAndWait();
final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart();
final WebSocket webSocket = httpClient.createWebSocket("/foo");
webSocket.setBinaryMessageConsumer(message -> {
messageRef.set(message);
countDownLatch.countDown();
});
webSocket.openAndWait();
webSocket.sendBinary("hello".getBytes());
countDownLatch.await(5, TimeUnit.SECONDS);
assertEquals("world", new String(messageRef.get(), StandardCharsets.UTF_8));
assertEquals("hello", new String(((byte[]) bodyRef.get()), StandardCharsets.UTF_8));
}
代码示例来源:origin: advantageous/qbit
@Test
public void testText() throws Exception {
final int port = PortUtils.findOpenPortStartAt(4000);
final HttpServer httpServer = HttpServerBuilder.httpServerBuilder().setPort(port).build();
final AtomicReference<Object> bodyRef = new AtomicReference<>();
final AtomicReference<String> messageRef = new AtomicReference<>();
final CountDownLatch countDownLatch = new CountDownLatch(2);
httpServer.setWebSocketMessageConsumer(webSocketMessage -> {
bodyRef.set(webSocketMessage.body());
webSocketMessage.getSender().sendText("world");
countDownLatch.countDown();
});
httpServer.startServerAndWait();
final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart();
final WebSocket webSocket = httpClient.createWebSocket("/foo");
webSocket.setTextMessageConsumer(message -> {
messageRef.set(message);
countDownLatch.countDown();
});
webSocket.openAndWait();
webSocket.sendText("hello");
countDownLatch.await(5, TimeUnit.SECONDS);
assertEquals("world", messageRef.get());
assertEquals("hello", bodyRef.get().toString());
}
代码示例来源:origin: advantageous/qbit
@Test
public void testNewOpenWaitWebSocketNewServerStuff() {
connect();
server.setWebSocketOnOpenConsumer(webSocket -> webSocket.setTextMessageConsumer(message -> {
if (message.equals("What do you want on your cheeseburger?")) {
webSocket.sendText("Bacon");
requestReceived.set(true);
} else {
puts("Websocket message", message);
}
}));
run();
final WebSocket webSocket = client.createWebSocket("/services/cheeseburger");
webSocket.setTextMessageConsumer(message -> {
if (message.equals("Bacon")) {
responseReceived.set(true);
}
});
webSocket.openAndWait();
webSocket.sendText("What do you want on your cheeseburger?");
client.flush();
validate();
stop();
}
代码示例来源:origin: advantageous/qbit
@Test
public void testTextQueue() throws Exception {
final int port = PortUtils.findOpenPortStartAt(4000);
final HttpServer httpServer = HttpServerBuilder.httpServerBuilder().setPort(port).build();
final AtomicReference<Object> bodyRef = new AtomicReference<>();
httpServer.setWebSocketMessageConsumer(webSocketMessage -> {
bodyRef.set(webSocketMessage.body());
webSocketMessage.getSender().sendText("world");
});
httpServer.startServerAndWait();
final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart();
final WebSocket webSocket = httpClient.createWebSocket("/foo");
final WebSocketTextQueue queue = new WebSocketTextQueue(webSocket);
webSocket.openAndWait();
webSocket.sendText("hello");
String message = queue.receiveQueue().pollWait();
assertEquals("world", message);
assertEquals("hello", bodyRef.get().toString());
}
代码示例来源:origin: advantageous/qbit
@Test
public void testTextQueueWithBatchSize() throws Exception {
final int port = PortUtils.findOpenPortStartAt(4000);
final HttpServer httpServer = HttpServerBuilder.httpServerBuilder().setPort(port).build();
final AtomicReference<Object> bodyRef = new AtomicReference<>();
httpServer.setWebSocketMessageConsumer(webSocketMessage -> {
bodyRef.set(webSocketMessage.body());
webSocketMessage.getSender().sendText("world");
});
httpServer.startServerAndWait();
final HttpClient httpClient = HttpClientBuilder.httpClientBuilder().setPort(port).buildAndStart();
final WebSocket webSocket = httpClient.createWebSocket("/foo");
final WebSocketTextQueue queue = new WebSocketTextQueue(webSocket, 100, 100, TimeUnit.MILLISECONDS);
webSocket.openAndWait();
webSocket.sendText("hello");
String message = queue.receiveQueue().pollWait();
assertEquals("world", message);
assertEquals("hello", bodyRef.get().toString());
}
代码示例来源:origin: advantageous/qbit
@Test
public void testNewOpenWaitWebSocket() {
connect();
server.setWebSocketMessageConsumer(webSocketMessage -> {
puts(webSocketMessage.address(), webSocketMessage.body());
if (webSocketMessage.getMessage().equals("What do you want on your cheeseburger?")) {
webSocketMessage.getSender().sendText("Bacon");
requestReceived.set(true);
} else {
puts("Websocket message", webSocketMessage.getMessage());
}
});
run();
final WebSocket webSocket = client.createWebSocket("/services/cheeseburger");
webSocket.setTextMessageConsumer(message -> {
if (message.equals("Bacon")) {
responseReceived.set(true);
}
});
webSocket.openAndWait();
webSocket.sendText("What do you want on your cheeseburger?");
client.flush();
validate();
stop();
}
代码示例来源:origin: advantageous/qbit
public static void main(String... args) {
final HttpClient httpClient = httpClientBuilder().setAutoFlush(true).setPort(9999).build();
httpClient.startClient();
final WebSocket webSocket = httpClient.createWebSocket("/hello");
webSocket.setTextMessageConsumer(message ->
puts("\n\n\n", message, "\n\n")
);
webSocket.openAndWait();
webSocket.sendText("Hello");
Sys.sleep(100000);
}
}
代码示例来源:origin: com.github.advantageous/qbit-core
wireWebSocket(serviceName, message);
try {
this.webSocket.openAndWait();
this.connected.set(true);
try {
if (webSocket.isClosed() && connected()) {
this.webSocket.openAndWait();
this.connected.set(true);
内容来源于网络,如有侵权,请联系作者删除!