コード例 #1
0
ファイル: PreyApp.java プロジェクト: JoyceYao/evasion
 public void setUpConnection(String playerDest, String publDest) {
   try {
     publClient.start();
     playerClient.start();
     URI publURI = new URI(publDest);
     URI playerURI = new URI(playerDest);
     ClientUpgradeRequest publRequest = new ClientUpgradeRequest();
     ClientUpgradeRequest playerRequest = new ClientUpgradeRequest();
     publClient.connect(publSocket, publURI, publRequest);
     playerClient.connect(playerSocket, playerURI, playerRequest);
   } catch (Throwable t) {
     t.printStackTrace();
   }
 }
コード例 #2
0
  private ServiceSocket getConnectionSocket() throws URISyntaxException, Exception {
    URI uri = getUri();

    String connectionId = getThreadName() + getConnectionId();
    ServiceSocket socket;
    WebSocketClient webSocketClient;
    if (isStreamingConnection()) {
      if (connectionList.containsKey(connectionId)) {
        socket = connectionList.get(connectionId);
        socket.initialize();
        return socket;
      } else {
        socket = new ServiceSocket(this);
        connectionList.put(connectionId, socket);
      }
    } else {
      socket = new ServiceSocket(this);
    }

    SslContextFactory sslContexFactory = new SslContextFactory();
    sslContexFactory.setTrustAll(isIgnoreSslErrors());
    webSocketClient = new WebSocketClient(sslContexFactory);

    webSocketClient.start();
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    webSocketClient.connect(socket, uri, request);

    int connectionTimeout = Integer.parseInt(getConnectionTimeout());
    socket.awaitOpen(connectionTimeout, TimeUnit.MILLISECONDS);

    return socket;
  }
コード例 #3
0
  @Test
  public void testEchoReturn() throws Exception {
    WSServer wsb = new WSServer(testdir, "app");
    wsb.copyWebInf("empty-web.xml");
    wsb.copyClass(EchoReturnEndpoint.class);

    try {
      wsb.start();
      URI uri = wsb.getServerBaseURI();

      WebAppContext webapp = wsb.createWebAppContext();
      wsb.deployWebapp(webapp);
      wsb.dump();

      WebSocketClient client = new WebSocketClient();
      try {
        client.start();
        JettyEchoSocket clientEcho = new JettyEchoSocket();
        Future<Session> future = client.connect(clientEcho, uri.resolve("echoreturn"));
        // wait for connect
        future.get(1, TimeUnit.SECONDS);
        clientEcho.sendMessage("Hello World");
        Queue<String> msgs = clientEcho.awaitMessages(1);
        Assert.assertEquals("Expected message", "Hello World", msgs.poll());
      } finally {
        client.stop();
      }
    } finally {
      wsb.stop();
    }
  }
コード例 #4
0
ファイル: WampJettyFactory.java プロジェクト: ghetolay/jwamp
  protected void connect(URI uri, long timeout, JettyConnection connection) throws Exception {

    if (!getWebsocketClient().isStarted()) websocketClient.start();

    ClientUpgradeRequest request = new ClientUpgradeRequest();
    request.setSubProtocols(WampFactory.getProtocolName());

    Future<Session> future = websocketClient.connect(connection, uri, request);

    if (timeout > 0) future.get(timeout, TimeUnit.MILLISECONDS);
    else future.get();
  }
コード例 #5
0
  public Session connect(AgentWebSocketClientController controller) throws Exception {
    if (webSocketClient == null || !webSocketClient.isRunning()) {
      if (webSocketClient != null) {
        webSocketClient.stop();
      }
      webSocketClient = builder.build();
      webSocketClient.start();
    }

    LOG.info("Connecting to websocket endpoint: " + urlService.getAgentRemoteWebSocketUrl());
    ClientUpgradeRequest request = new ClientUpgradeRequest();
    request.addExtensions("fragment;maxLength=" + getMessageBufferSize());
    return webSocketClient
        .connect(controller, new URI(urlService.getAgentRemoteWebSocketUrl()), request)
        .get();
  }