首先这个是从play.server.Server.main函数中启动的(端口号时9000,使用netty来实现连接的)
Server
public static void main(String[] args) throws Exception {
//获取项目路径 C:\Users\Administrator\Test
File root = new File(System.getProperty("application.path"));
//初始化
Play.init(root, System.getProperty("play.id", ""));
//创建
if (System.getProperty("precompile") == null)
new Server(args);
}
下面来看具体的操作(netty 端口号9000)
public static int httpPort;//http端口号
public static int httpsPort;//https端口号
public Server() {
httpPort = Integer.parseInt(p.getProperty("http.port", "-1"));
httpsPort = Integer.parseInt(p.getProperty("https.port", "-1"));
if (httpPort == -1 && httpsPort == -1)
httpPort = 9000;
//地址
InetAddress address = null;
InetAddress secureAddress = null;
if (p.getProperty("http.address") != null)
address = InetAddress.getByName(p.getProperty("http.address"));
if (p.getProperty("https.address") != null)
secureAddress = InetAddress.getByName(p.getProperty("https.address"));
//开启服务
if (httpPort != -1)
openNettyServer(httpPort, address ,false);
if (httpsPort != -1)
openNettyServer(httpsPort, address ,true);
}
//开启服务
private void openNettyServer(int port,InetAddress address, boolean isHttps) {
ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(Executors.newCachedThreadPool(), Executors.newCachedThreadPool());
bootstrap.setPipelineFactory(isHttps ? new SslHttpServerPipelineFactory() : newHttpServerPipelineFactory());
bootstrap.bind(new InetSocketAddress(address, port));
bootstrap.setOption("child.tcpNoDelay", true);
}
http是HttpServerPipelineFactory,https是SslHttpServerPipelineFactory