本文整理汇总了Java中javax.websocket.WebSocketContainer.setDefaultMaxBinaryMessageBufferSize方法的典型用法代码示例。如果您正苦于以下问题:Java WebSocketContainer.setDefaultMaxBinaryMessageBufferSize方法的具体用法?Java WebSocketContainer.setDefaultMaxBinaryMessageBufferSize怎么用?Java WebSocketContainer.setDefaultMaxBinaryMessageBufferSize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.websocket.WebSocketContainer
的用法示例。
在下文中一共展示了WebSocketContainer.setDefaultMaxBinaryMessageBufferSize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testConnectToServerEndpoint
import javax.websocket.WebSocketContainer; //导入方法依赖的package包/类
@Test
public void testConnectToServerEndpoint() throws Exception {
Tomcat tomcat = getTomcatInstance();
// No file system docBase required
Context ctx = tomcat.addContext("", null);
ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketContainer wsContainer =
ContainerProvider.getWebSocketContainer();
// Set this artificially small to trigger
// https://bz.apache.org/bugzilla/show_bug.cgi?id=57054
wsContainer.setDefaultMaxBinaryMessageBufferSize(64);
Session wsSession = wsContainer.connectToServer(
TesterProgrammaticEndpoint.class,
ClientEndpointConfig.Builder.create().build(),
new URI("ws://" + getHostName() + ":" + getPort() +
TesterEchoServer.Config.PATH_ASYNC));
CountDownLatch latch = new CountDownLatch(1);
BasicText handler = new BasicText(latch);
wsSession.addMessageHandler(handler);
wsSession.getBasicRemote().sendText(MESSAGE_STRING_1);
boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);
Assert.assertTrue(latchResult);
Queue<String> messages = handler.getMessages();
Assert.assertEquals(1, messages.size());
Assert.assertEquals(MESSAGE_STRING_1, messages.peek());
((WsWebSocketContainer) wsContainer).destroy();
}
示例2: testConnectToServerEndpoint
import javax.websocket.WebSocketContainer; //导入方法依赖的package包/类
@Test
public void testConnectToServerEndpoint() throws Exception {
Tomcat tomcat = getTomcatInstance();
// Must have a real docBase - just use temp
Context ctx =
tomcat.addContext("", System.getProperty("java.io.tmpdir"));
ctx.addApplicationListener(TesterEchoServer.Config.class.getName());
Tomcat.addServlet(ctx, "default", new DefaultServlet());
ctx.addServletMapping("/", "default");
tomcat.start();
WebSocketContainer wsContainer =
ContainerProvider.getWebSocketContainer();
// Set this artificially small to trigger
// https://issues.apache.org/bugzilla/show_bug.cgi?id=57054
wsContainer.setDefaultMaxBinaryMessageBufferSize(64);
Session wsSession = wsContainer.connectToServer(
TesterProgrammaticEndpoint.class,
ClientEndpointConfig.Builder.create().build(),
new URI("ws://localhost:" + getPort() +
TesterEchoServer.Config.PATH_ASYNC));
CountDownLatch latch = new CountDownLatch(1);
BasicText handler = new BasicText(latch);
wsSession.addMessageHandler(handler);
wsSession.getBasicRemote().sendText(MESSAGE_STRING_1);
boolean latchResult = handler.getLatch().await(10, TimeUnit.SECONDS);
Assert.assertTrue(latchResult);
Queue<String> messages = handler.getMessages();
Assert.assertEquals(1, messages.size());
Assert.assertEquals(MESSAGE_STRING_1, messages.peek());
((WsWebSocketContainer) wsContainer).destroy();
}