?????????????????????????дC++???????????Java?????????Netty??Netty?????????????д?????????????????????????Щ???????????????????????
?????????????????????????????????????????ó?????
????· ???????????????δ????
????· ??????????
???????ж??????????????LoginServer??GameServer????????????????????????????
??????????????н????????????????Netty??????????£?
????ctx.channel().eventLoop().schedule(() -> tryConnect()?? reconnectInterval?? TimeUnit.SECONDS);
????tryConnect????????????????????????????????????reconnectInterval????????μ????tryConnect?????????????????ó?????????connect????channel inactive?????????????
???????????????????????????????ι????????Netty???Channel???????????????????????????????????????????Session????????????????????????????????????????????????????????????????????Channel?????????Session???????????????
?????????????δ??????Session??
??????????Netty??ú???????????????TcpServer/TcpClient???????????????????????????? TcpServer??TcpClient?????????????????Session?????????????Netty??????????????????ServerBootstrap??Bootstrap?????????bind??connect???????δ??????
????Session???????ListenSession???????????????TransmitSession????????????????????У?????????????????GameServer????????LoginServer?????GameServer?????client?????????????????GameServer????????????????LoginServer??LoginServer??????????????????顣?????GameServer??????????Client??????????????????????Gateway?????????????????????client???????????TransmitSession????????????????????????????????????????????????????Active??????????????Server??TransmitSession??????????????????TransmitSession????ClientSession??ServerSession??SeverSession??TcpServer?????????????????????ListenSession??ClientSession????????????д?????????TcpServer/TcpClient?????
??????????£?
public abstract class ListenSession {
private boolean working = false;
private int localPort = 0;
private int relistenInterval = 10;
...
public abstract ServerSession createServerSession();
}
public abstract class TransmitSession {
protected Channel channel = null;
protected boolean working = false;
...
public abstract void onActive() throws Exception;
public abstract void onInactive() throws Exception;
public abstract void onException() throws Exception;
public abstract void onReceive(Object data) throws Exception;
public abstract void send(Object data);
}
public abstract class ClientSession extends TransmitSession {
private String remoteHost = "";
private int remotePort = 0;
private int reconnectInterval = 10;
...
}
??????ο?????ι???Channel??Session???????????????????????HashMap????????????????????????????????Session?????Channel????????????????β?????????Netty??????????Channel??AttrMap???????????????????client??connect?????Channel??Active/Inactive???Channel?????????????????????/??????????server??bind?????Channel???????ListenSession??Active/Inactive???Channel???????μ??????bind??Channel???????????????ListenSession?????Netty??????????????Channel.parent()??????????Active???Channel????bind???Channel?????????????????parent??