コード例 #1
0
 public WebSocketClientConnection(
     EndPoint endp, Executor executor, DefaultWebSocketClient client) {
   super(
       endp,
       executor,
       client.getFactory().getScheduler(),
       client.getPolicy(),
       client.getFactory().getBufferPool());
   this.client = client;
   this.factory = client.getFactory();
   this.connected = false;
   this.masker = client.getMasker();
 }
コード例 #2
0
  private void upgradeConnection(ClientUpgradeResponse response) {
    EndPoint endp = getEndPoint();
    Executor executor = getExecutor();
    WebSocketClientConnection connection = new WebSocketClientConnection(endp, executor, client);

    // Initialize / Negotiate Extensions
    EventDriver websocket = client.getWebSocket();
    WebSocketPolicy policy = client.getPolicy();
    String acceptedSubProtocol = response.getAcceptedSubProtocol();

    WebSocketSession session = new WebSocketSession(request.getRequestURI(), websocket, connection);
    session.setPolicy(policy);
    session.setNegotiatedSubprotocol(acceptedSubProtocol);

    connection.setSession(session);
    List<Extension> extensions = client.getFactory().initExtensions(response.getExtensions());

    // Start with default routing.
    IncomingFrames incoming = session;
    // OutgoingFrames outgoing = connection;

    // Connect extensions
    if (extensions != null) {
      connection.getParser().configureFromExtensions(extensions);
      connection.getGenerator().configureFromExtensions(extensions);

      // FIXME
      // Iterator<Extension> extIter;
      // // Connect outgoings
      // extIter = extensions.iterator();
      // while (extIter.hasNext())
      // {
      // Extension ext = extIter.next();
      // ext.setNextOutgoingFrames(outgoing);
      // outgoing = ext;
      // }
      //
      // // Connect incomings
      // Collections.reverse(extensions);
      // extIter = extensions.iterator();
      // while (extIter.hasNext())
      // {
      // Extension ext = extIter.next();
      // ext.setNextIncomingFrames(incoming);
      // incoming = ext;
      // }
    }

    // configure session for outgoing flows
    // session.setOutgoing(outgoing);
    // configure connection for incoming flows
    connection.getParser().setIncomingFramesHandler(incoming);

    // Now swap out the connection
    endp.setConnection(connection);
    connection.onOpen();
  }
コード例 #3
0
  public UpgradeConnection(EndPoint endp, Executor executor, DefaultWebSocketClient client) {
    super(endp, executor);
    this.client = client;
    this.bufferPool = client.getFactory().getBufferPool();
    this.parser = new HttpResponseHeaderParser();

    try {
      this.request = client.getUpgradeRequest();
    } catch (ClassCastException e) {
      client.failed(new RuntimeException("Invalid Upgrade Request structure", e));
    }
  }