Package fi.iki.elonen

Class NanoWSD

    • Field Detail

      • LOG

        private static final java.util.logging.Logger LOG
        logger to log to.
      • HEADER_UPGRADE_VALUE

        public static final java.lang.String HEADER_UPGRADE_VALUE
        See Also:
        Constant Field Values
      • HEADER_CONNECTION

        public static final java.lang.String HEADER_CONNECTION
        See Also:
        Constant Field Values
      • HEADER_CONNECTION_VALUE

        public static final java.lang.String HEADER_CONNECTION_VALUE
        See Also:
        Constant Field Values
      • HEADER_WEBSOCKET_VERSION

        public static final java.lang.String HEADER_WEBSOCKET_VERSION
        See Also:
        Constant Field Values
      • HEADER_WEBSOCKET_VERSION_VALUE

        public static final java.lang.String HEADER_WEBSOCKET_VERSION_VALUE
        See Also:
        Constant Field Values
      • HEADER_WEBSOCKET_KEY

        public static final java.lang.String HEADER_WEBSOCKET_KEY
        See Also:
        Constant Field Values
      • HEADER_WEBSOCKET_ACCEPT

        public static final java.lang.String HEADER_WEBSOCKET_ACCEPT
        See Also:
        Constant Field Values
      • HEADER_WEBSOCKET_PROTOCOL

        public static final java.lang.String HEADER_WEBSOCKET_PROTOCOL
        See Also:
        Constant Field Values
      • WEBSOCKET_KEY_MAGIC

        private static final java.lang.String WEBSOCKET_KEY_MAGIC
        See Also:
        Constant Field Values
      • ALPHABET

        private static final char[] ALPHABET
    • Constructor Detail

      • NanoWSD

        public NanoWSD​(int port)
      • NanoWSD

        public NanoWSD​(java.lang.String hostname,
                       int port)
    • Method Detail

      • encodeBase64

        private static java.lang.String encodeBase64​(byte[] buf)
        Translates the specified byte array into Base64 string.

        Android has android.util.Base64, sun has sun.misc.Base64Encoder, Java 8 hast java.util.Base64, I have this from stackoverflow: http://stackoverflow.com/a/4265472

        Parameters:
        buf - the byte array (not null)
        Returns:
        the translated Base64 string (not null)
      • makeAcceptKey

        public static java.lang.String makeAcceptKey​(java.lang.String key)
                                              throws java.security.NoSuchAlgorithmException
        Throws:
        java.security.NoSuchAlgorithmException
      • isWebSocketConnectionHeader

        private boolean isWebSocketConnectionHeader​(java.util.Map<java.lang.String,​java.lang.String> headers)
      • serve

        public NanoHTTPD.Response serve​(NanoHTTPD.IHTTPSession session)
        Description copied from class: NanoHTTPD
        Override this to customize the server.

        (By default, this returns a 404 "Not Found" plain text error response.)

        Overrides:
        serve in class NanoHTTPD
        Parameters:
        session - The HTTP session
        Returns:
        HTTP response, see class Response for details
      • useGzipWhenAccepted

        protected boolean useGzipWhenAccepted​(NanoHTTPD.Response r)
        not all websockets implementations accept gzip compression.
        Overrides:
        useGzipWhenAccepted in class NanoHTTPD
        Returns:
        true if the gzip compression should be used if the client accespts it. Default this option is on for text content and off for everything. Override this for custom semantics.