本文整理匯總了Java中fi.iki.elonen.NanoHTTPD.start方法的典型用法代碼示例。如果您正苦於以下問題:Java NanoHTTPD.start方法的具體用法?Java NanoHTTPD.start怎麽用?Java NanoHTTPD.start使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類fi.iki.elonen.NanoHTTPD
的用法示例。
在下文中一共展示了NanoHTTPD.start方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: authorizeAt
import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
/**
* This set up a server from the {@link #redirectUrl} and bind to the specified port.
* Then the server will wait for users' authorization. If a user authorized the application,
* the server will get a redirected url with the authorization code as a query param, then cache the user.
*
* @param port The port.
* @return OAuth for chaining.
*/
public OAuth authorizeAt(int port) {
try {
NanoHTTPD server = new NanoHTTPD(port) {
@Override
public Response serve(IHTTPSession session) {
if (session.getParms().get("code") != null) {
authorize(session.getParms().get("code"));
System.out.println(session.getParms().get("code"));
} else if (session.getParms().get("error") != null) {
// TODO: throw errors
System.out.println(session.getParms().get("error"));
}
return null;
}
};
server.start();
} catch (IOException e) {
// TODO: throw errors
e.printStackTrace();
}
return this;
}
示例2: executeInstance
import fi.iki.elonen.NanoHTTPD; //導入方法依賴的package包/類
public static void executeInstance(NanoHTTPD server) {
try {
server.start(NanoHTTPD.SOCKET_READ_TIMEOUT, false);
} catch (IOException ioe) {
System.err.println("Couldn't start server:\n" + ioe);
System.exit(-1);
}
System.out.println("Server started, Hit Enter to stop.\n");
try {
System.in.read();
} catch (Throwable ignored) {
}
server.stop();
System.out.println("Server stopped.\n");
}