Package org.jwebsocket.api

Examples of org.jwebsocket.api.WebSocketEngine


  public WebSocketEngine initializeEngine() {
    if (log.isDebugEnabled()) {
      log.debug("Instantiating engine...");
    }
    EngineConfiguration config = getEngineConfiguration();
    WebSocketEngine newEngine = null;
    try {
      newEngine = new TCPEngine(config);
      //newEngine = new NettyEngine(config);
    } catch (Exception e) {
      System.out.println("Error instantiating engine: " + e.getMessage());
      System.exit(0);
    }
    if (log.isInfoEnabled()) {
      log.info("Engine " + newEngine.getId() + " instantiated.");
    }
    return newEngine;
  }
View Full Code Here


   * {@inheritDoc}
   */
  @SuppressWarnings("unchecked")
  @Override
  public WebSocketEngine initializeEngine() {
    WebSocketEngine newEngine = null;
    EngineConfig engineConfig = mConfig.getEngines().get(0);
    String jarFilePath = "-";
    try {
      Class lEngineClass = null;

View Full Code Here

      connector = aConnector;
    }

    @Override
    public void run() {
      WebSocketEngine engine = getEngine();

      int lMaxFrameSize = JWebSocketCommonConstants.DEFAULT_MAX_FRAME_SIZE;
      EngineConfiguration config = engine.getConfiguration();
      if (config != null && config.getMaxFramesize() > 0) {
        lMaxFrameSize = config.getMaxFramesize();
      }
      byte[] lBuff = new byte[lMaxFrameSize];
      int pos = -1;
      int lStart = -1;

      try {
        // start client listener loop
        mIsRunning = true;

        // call connectorStarted method of engine
        engine.connectorStarted(connector);

        while (mIsRunning) {
          try {
            int b = mIn.read();
            // start of frame
            if (b == 0x00) {
              pos = 0;
              lStart = 0;
              // end of frame
            } else if (b == 0xff) {
              if (lStart >= 0) {
                if (pos <= lMaxFrameSize) {
                  RawPacket lPacket = new RawPacket(Arrays.copyOf(lBuff, pos));
                  try {
                    engine.processPacket(connector, lPacket);
                  } catch (Exception ex) {
                    mLog.error(ex.getClass().getSimpleName()
                        + " in processPacket of connector "
                        + connector.getClass().getSimpleName()
                        + ": " + ex.getMessage());
                  }
                } else {
                  mLog.error("Datapacket exceeded maximum size of " + lMaxFrameSize + " bytes and will not be processed!");
                }
              }
              lStart = -1;
              // end of stream
            } else if (b < 0) {
              mCloseReason = CloseReason.CLIENT;
              mIsRunning = false;
              // any other byte within or outside a frame
            } else {
              if (lStart >= 0 && pos < lMaxFrameSize) {
                lBuff[pos] = (byte) b;
              }
              pos++;
            }
          } catch (SocketTimeoutException ex) {
            mLog.error("(timeout) "
                + ex.getClass().getSimpleName()
                + ": " + ex.getMessage());
            mCloseReason = CloseReason.TIMEOUT;
            mIsRunning = false;
          } catch (Exception ex) {
            mLog.error("(other) "
                + ex.getClass().getSimpleName()
                + ": " + ex.getMessage());
            mCloseReason = CloseReason.SERVER;
            mIsRunning = false;
          }
        }

        // call client stopped method of engine
        // (e.g. to release client from streams)
        engine.connectorStopped(connector, mCloseReason);

        // br.close();
        mIn.close();
        mOut.close();
        mClientSocket.close();
View Full Code Here

   * @param aEngine id of the engine of the connector.
   * @param aId id of the connector to be returned
   * @return WebSocketConnector with the given id or <tt>null</tt> if not found.
   */
  public WebSocketConnector getConnector(String aEngine, String aId) {
    WebSocketEngine lEngine = mEngines.get(aEngine);
    if (lEngine != null) {
      return lEngine.getConnectors().get(aId);
    }
    return null;
  }
View Full Code Here

TOP

Related Classes of org.jwebsocket.api.WebSocketEngine

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.