mirror of
https://github.com/GravitLauncher/Launcher
synced 2025-03-31 13:38:06 +03:00
Тестовая команда "test start" для старта сервера netty
This commit is contained in:
parent
e16145cb6b
commit
4e739a74b5
3 changed files with 14 additions and 10 deletions
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
import ru.gravit.launchserver.LaunchServer;
|
import ru.gravit.launchserver.LaunchServer;
|
||||||
import ru.gravit.launchserver.command.Command;
|
import ru.gravit.launchserver.command.Command;
|
||||||
|
import ru.gravit.launchserver.socket.NettyServerSocketHandler;
|
||||||
import ru.gravit.utils.HttpDownloader;
|
import ru.gravit.utils.HttpDownloader;
|
||||||
import ru.gravit.utils.helper.LogHelper;
|
import ru.gravit.utils.helper.LogHelper;
|
||||||
|
|
||||||
|
@ -11,7 +12,7 @@ public class TestCommand extends Command {
|
||||||
public TestCommand(LaunchServer server) {
|
public TestCommand(LaunchServer server) {
|
||||||
super(server);
|
super(server);
|
||||||
}
|
}
|
||||||
|
NettyServerSocketHandler handler;
|
||||||
@Override
|
@Override
|
||||||
public String getArgsDescription() {
|
public String getArgsDescription() {
|
||||||
return null;
|
return null;
|
||||||
|
@ -25,8 +26,11 @@ public String getUsageDescription() {
|
||||||
@Override
|
@Override
|
||||||
public void invoke(String... args) throws Exception {
|
public void invoke(String... args) throws Exception {
|
||||||
verifyArgs(args,1);
|
verifyArgs(args,1);
|
||||||
LogHelper.debug("start downloading");
|
if(handler == null)
|
||||||
HttpDownloader downloader =new HttpDownloader(new URL(args[0]),"test.html");
|
handler = new NettyServerSocketHandler(server);
|
||||||
LogHelper.debug("end downloading");
|
if(args[0].equals("start"))
|
||||||
|
{
|
||||||
|
handler.run();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@
|
||||||
import javax.net.ssl.*;
|
import javax.net.ssl.*;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
|
import java.net.InetSocketAddress;
|
||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
import java.nio.channels.Selector;
|
import java.nio.channels.Selector;
|
||||||
|
@ -100,7 +101,7 @@ public SSLContext SSLContextInit() throws NoSuchAlgorithmException, Unrecoverabl
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
SSLContext sc = null;
|
/*SSLContext sc = null;
|
||||||
try {
|
try {
|
||||||
sc = SSLContextInit();
|
sc = SSLContextInit();
|
||||||
} catch (NoSuchAlgorithmException e) {
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
@ -115,7 +116,7 @@ public void run() {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (CertificateException e) {
|
} catch (CertificateException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}*/
|
||||||
//System.setProperty( "javax.net.ssl.keyStore","keystore");
|
//System.setProperty( "javax.net.ssl.keyStore","keystore");
|
||||||
//System.setProperty( "javax.net.ssl.keyStorePassword","PSP1000");
|
//System.setProperty( "javax.net.ssl.keyStorePassword","PSP1000");
|
||||||
try {
|
try {
|
||||||
|
@ -126,8 +127,8 @@ public void run() {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
LogHelper.info("Starting server socket thread");
|
LogHelper.info("Starting server socket thread");
|
||||||
SSLEngine engine = sc.createSSLEngine();
|
//SSLEngine engine = sc.createSSLEngine();
|
||||||
engine.setUseClientMode(false);
|
//engine.setUseClientMode(false);
|
||||||
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
EventLoopGroup bossGroup = new NioEventLoopGroup();
|
||||||
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
EventLoopGroup workerGroup = new NioEventLoopGroup();
|
||||||
try {
|
try {
|
||||||
|
@ -149,7 +150,7 @@ public void initChannel(NioSocketChannel ch) throws Exception {
|
||||||
pipeline.addLast(new WebSocketFrameHandler());
|
pipeline.addLast(new WebSocketFrameHandler());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
ChannelFuture f = b.bind(server.config.getSocketAddress()).sync();
|
ChannelFuture f = b.bind(new InetSocketAddress(9876)).sync(); //TEST ONLY!
|
||||||
f.channel().closeFuture().sync();
|
f.channel().closeFuture().sync();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
|
|
@ -15,7 +15,6 @@ public class WebSocketFrameHandler extends SimpleChannelInboundHandler<WebSocket
|
||||||
|
|
||||||
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
|
protected void channelRead0(ChannelHandlerContext ctx, WebSocketFrame frame) throws Exception {
|
||||||
// ping and pong frames already handled
|
// ping and pong frames already handled
|
||||||
|
|
||||||
if (frame instanceof TextWebSocketFrame) {
|
if (frame instanceof TextWebSocketFrame) {
|
||||||
// Send the uppercase string back.
|
// Send the uppercase string back.
|
||||||
String request = ((TextWebSocketFrame) frame).text();
|
String request = ((TextWebSocketFrame) frame).text();
|
||||||
|
|
Loading…
Reference in a new issue