Package fi.iki.elonen

Class NanoWSD

Direct Known Subclasses:
DebugWebSocketServer

public abstract class NanoWSD extends NanoHTTPD
  • Field Details

  • Constructor Details

    • NanoWSD

      public NanoWSD(int port)
    • NanoWSD

      public NanoWSD(String hostname, int port)
  • Method Details

    • encodeBase64

      private static 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 String makeAcceptKey(String key) throws NoSuchAlgorithmException
      Throws:
      NoSuchAlgorithmException
    • isWebSocketConnectionHeader

      private boolean isWebSocketConnectionHeader(Map<String,String> headers)
    • isWebsocketRequested

      protected boolean isWebsocketRequested(NanoHTTPD.IHTTPSession session)
    • openWebSocket

      protected abstract NanoWSD.WebSocket openWebSocket(NanoHTTPD.IHTTPSession handshake)
    • serve

      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
    • serveHttp

      protected NanoHTTPD.Response serveHttp(NanoHTTPD.IHTTPSession session)
    • 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.