use of javax.websocket.Session in project jetty.project by eclipse.
the class EndpointEchoTest method testBasicEchoClassref.
@Test
public void testBasicEchoClassref() throws Exception {
WebSocketContainer container = ContainerProvider.getWebSocketContainer();
// Issue connect using class reference (class extends Endpoint)
Session session = container.connectToServer(EndpointEchoClient.class, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
session.getBasicRemote().sendText("Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
// TODO: figure out echo verification.
// echoer.textCapture.messageQueue.awaitMessages(1,1000,TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class MessageReceivingTest method testWholeBinaryMessage.
/**
* Method tests receiving of binary messages at once.
*
* @throws Exception on exception occur
*/
@Test
public void testWholeBinaryMessage() throws Exception {
final TestEndpoint echoer = new TestEndpoint(new WholeByteBufferCaptureHandler());
Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
// Issue connect using instance of class that extends Endpoint
final Session session = container.connectToServer(echoer, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
sendBinary(session, "");
sendBinary(session, "Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
echoer.handler.getMessageQueue().awaitMessages(2, 1000, TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project jetty.project by eclipse.
the class MessageReceivingTest method testPartialBinaryMessage.
/**
* Method tests receiving of binary messages by parts.
*
* @throws Exception on exception occur
*/
@Test
public void testPartialBinaryMessage() throws Exception {
final TestEndpoint echoer = new TestEndpoint(new PartialByteBufferCaptureHandler());
Assert.assertThat(echoer, instanceOf(javax.websocket.Endpoint.class));
// Issue connect using instance of class that extends Endpoint
final Session session = container.connectToServer(echoer, serverUri);
if (LOG.isDebugEnabled())
LOG.debug("Client Connected: {}", session);
sendBinary(session, "");
sendBinary(session, "Echo");
if (LOG.isDebugEnabled())
LOG.debug("Client Message Sent");
echoer.handler.getMessageQueue().awaitMessages(2, 1000, TimeUnit.MILLISECONDS);
}
use of javax.websocket.Session in project javaee7-samples by javaee-samples.
the class MyEndpointTest method testTextEndpoint.
@Test
public void testTextEndpoint() throws URISyntaxException, DeploymentException, IOException, InterruptedException {
MyEndpointTextClient.latch = new CountDownLatch(1);
final String TEXT = "Hello World!";
Session session = connectToServer(MyEndpointTextClient.class);
assertNotNull(session);
session.addMessageHandler(new MessageHandler.Whole<String>() {
@Override
public void onMessage(String text) {
assertEquals(TEXT, text);
}
});
assertTrue(MyEndpointTextClient.latch.await(2, TimeUnit.SECONDS));
}
use of javax.websocket.Session in project javaee7-samples by javaee-samples.
the class GoogleDocClient method start.
@Override
public void start(Stage stage) throws Exception {
final Session session = connectToServer();
System.out.println("Connected to server: " + session.getId());
stage.setTitle("Google Docs Emulator using WebSocket");
textarea = new TextArea();
textarea.textProperty().addListener(new ChangeListener<String>() {
@Override
public void changed(ObservableValue<? extends String> observable, String oldValue, String newValue) {
System.out.println("New value: " + newValue);
try {
session.getBasicRemote().sendText(newValue);
} catch (IOException ex) {
Logger.getLogger(GoogleDocClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
});
textarea.setPrefSize(500, 300);
textarea.setWrapText(true);
Scene scene = new Scene(textarea);
stage.setScene(scene);
stage.show();
}
Aggregations