mirror of
https://github.com/tiennm99/caro.git
synced 2026-09-03 00:17:42 +00:00
服务端监控
This commit is contained in:
@@ -2,6 +2,7 @@ package org.nico.ratel.landlords.server;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.nico.ratel.landlords.print.SimplePrinter;
|
||||
import org.nico.ratel.landlords.server.handler.DefaultChannelInitializer;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
@@ -30,6 +31,8 @@ public class SimpleServer {
|
||||
.childHandler(new DefaultChannelInitializer());
|
||||
|
||||
ChannelFuture f = bootstrap .bind().sync();
|
||||
|
||||
SimplePrinter.printNotice("The server was successfully started on port " + ServerContains.port);
|
||||
f.channel().closeFuture().sync();
|
||||
} finally {
|
||||
parentGroup.shutdownGracefully();
|
||||
|
||||
+6
-4
@@ -25,7 +25,7 @@ public class TransferHandler extends ChannelInboundHandlerAdapter{
|
||||
ClientSide clientSide = new ClientSide(((InetSocketAddress)ch.remoteAddress()).getPort(), ClientStatus.TO_CHOOSE, ch);
|
||||
clientSide.setNickname(String.valueOf(clientSide.getId()));
|
||||
ServerContains.CLIENT_SIDE_MAP.put(clientSide.getId(), clientSide);
|
||||
SimplePrinter.printNotice("Has client connects to the server:" + clientSide.getId());
|
||||
SimplePrinter.printNotice("Has client connect to the server:" + clientSide.getId());
|
||||
|
||||
ChannelUtils.pushToClient(ch, ClientEventCode.CODE_CLIENT_CONNECT, String.valueOf(clientSide.getId()));
|
||||
ChannelUtils.pushToClient(ch, ClientEventCode.CODE_CLIENT_NICKNAME_SET, null);
|
||||
@@ -51,13 +51,15 @@ public class TransferHandler extends ChannelInboundHandlerAdapter{
|
||||
@Override
|
||||
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
|
||||
if(cause instanceof java.io.IOException) {
|
||||
ClientSide client = ServerContains.CLIENT_SIDE_MAP.get(((InetSocketAddress)ctx.channel().remoteAddress()).getPort());
|
||||
int clientId = ((InetSocketAddress)ctx.channel().remoteAddress()).getPort();
|
||||
ClientSide client = ServerContains.CLIENT_SIDE_MAP.get(clientId);
|
||||
if(client != null) {
|
||||
SimplePrinter.printNotice(client.getNickname() + " exit");
|
||||
SimplePrinter.printNotice("Has client exit to the server:" + clientId + " | " + client.getNickname());
|
||||
ServerEventListener.get(ServerEventCode.CODE_CLIENT_EXIT).call(client, null);
|
||||
}
|
||||
}else {
|
||||
SimplePrinter.printNotice("ERROR:" + cause.getMessage());
|
||||
}
|
||||
cause.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user