Package fi.iki.elonen
Class NanoWSD
- java.lang.Object
-
- fi.iki.elonen.NanoHTTPD
-
- fi.iki.elonen.NanoWSD
-
- Direct Known Subclasses:
DebugWebSocketServer
public abstract class NanoWSD extends NanoHTTPD
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
NanoWSD.State
static class
NanoWSD.WebSocket
static class
NanoWSD.WebSocketException
static class
NanoWSD.WebSocketFrame
-
Nested classes/interfaces inherited from class fi.iki.elonen.NanoHTTPD
NanoHTTPD.AsyncRunner, NanoHTTPD.ClientHandler, NanoHTTPD.ContentType, NanoHTTPD.Cookie, NanoHTTPD.CookieHandler, NanoHTTPD.DefaultAsyncRunner, NanoHTTPD.DefaultServerSocketFactory, NanoHTTPD.DefaultTempFile, NanoHTTPD.DefaultTempFileManager, NanoHTTPD.HTTPSession, NanoHTTPD.IHTTPSession, NanoHTTPD.Method, NanoHTTPD.Response, NanoHTTPD.ResponseException, NanoHTTPD.SecureServerSocketFactory, NanoHTTPD.ServerRunnable, NanoHTTPD.ServerSocketFactory, NanoHTTPD.TempFile, NanoHTTPD.TempFileManager, NanoHTTPD.TempFileManagerFactory
-
-
Field Summary
Fields Modifier and Type Field Description private static char[]
ALPHABET
static java.lang.String
HEADER_CONNECTION
static java.lang.String
HEADER_CONNECTION_VALUE
static java.lang.String
HEADER_UPGRADE
static java.lang.String
HEADER_UPGRADE_VALUE
static java.lang.String
HEADER_WEBSOCKET_ACCEPT
static java.lang.String
HEADER_WEBSOCKET_KEY
static java.lang.String
HEADER_WEBSOCKET_PROTOCOL
static java.lang.String
HEADER_WEBSOCKET_VERSION
static java.lang.String
HEADER_WEBSOCKET_VERSION_VALUE
private static java.util.logging.Logger
LOG
logger to log to.private static java.lang.String
WEBSOCKET_KEY_MAGIC
-
Fields inherited from class fi.iki.elonen.NanoHTTPD
asyncRunner, MIME_HTML, MIME_PLAINTEXT, MIME_TYPES, SOCKET_READ_TIMEOUT
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description private static java.lang.String
encodeBase64(byte[] buf)
Translates the specified byte array into Base64 string.private boolean
isWebSocketConnectionHeader(java.util.Map<java.lang.String,java.lang.String> headers)
protected boolean
isWebsocketRequested(NanoHTTPD.IHTTPSession session)
static java.lang.String
makeAcceptKey(java.lang.String key)
protected abstract NanoWSD.WebSocket
openWebSocket(NanoHTTPD.IHTTPSession handshake)
NanoHTTPD.Response
serve(NanoHTTPD.IHTTPSession session)
Override this to customize the server.protected NanoHTTPD.Response
serveHttp(NanoHTTPD.IHTTPSession session)
protected boolean
useGzipWhenAccepted(NanoHTTPD.Response r)
not all websockets implementations accept gzip compression.-
Methods inherited from class fi.iki.elonen.NanoHTTPD
closeAllConnections, createClientHandler, createServerRunnable, decodeParameters, decodeParameters, decodePercent, getHostname, getListeningPort, getMimeTypeForFile, getServerSocketFactory, getTempFileManagerFactory, isAlive, makeSecure, makeSSLSocketFactory, makeSSLSocketFactory, makeSSLSocketFactory, mimeTypes, newChunkedResponse, newFixedLengthResponse, newFixedLengthResponse, newFixedLengthResponse, serve, setAsyncRunner, setServerSocketFactory, setTempFileManagerFactory, start, start, start, stop, wasStarted
-
-
-
-
Field Detail
-
LOG
private static final java.util.logging.Logger LOG
logger to log to.
-
HEADER_UPGRADE
public static final java.lang.String HEADER_UPGRADE
- See Also:
- Constant Field Values
-
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
-
-
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)
-
isWebsocketRequested
protected boolean isWebsocketRequested(NanoHTTPD.IHTTPSession session)
-
openWebSocket
protected abstract NanoWSD.WebSocket openWebSocket(NanoHTTPD.IHTTPSession handshake)
-
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.)
-
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 classNanoHTTPD
- 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.
-
-