Initial Netty implementation for networking
Split into 1 LoginServer and 1 ChannelServer per channel. There is still a lot of cleanup and refactoring to be done. Currently, the reliance on IoSession holding client state is the most pressing issue to be addressed.
This commit is contained in:
40
src/main/java/net/netty/ChannelServer.java
Normal file
40
src/main/java/net/netty/ChannelServer.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package net.netty;
|
||||
|
||||
import io.netty.bootstrap.ServerBootstrap;
|
||||
import io.netty.channel.Channel;
|
||||
import io.netty.channel.EventLoopGroup;
|
||||
import io.netty.channel.nio.NioEventLoopGroup;
|
||||
import io.netty.channel.socket.nio.NioServerSocketChannel;
|
||||
|
||||
public class ChannelServer extends AbstractServer {
|
||||
private final int world;
|
||||
private final int channel;
|
||||
private Channel nettyChannel;
|
||||
|
||||
public ChannelServer(int port, int world, int channel) {
|
||||
super(port);
|
||||
this.world = world;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
EventLoopGroup parentGroup = new NioEventLoopGroup();
|
||||
EventLoopGroup childGroup = new NioEventLoopGroup();
|
||||
ServerBootstrap bootstrap = new ServerBootstrap()
|
||||
.group(parentGroup, childGroup)
|
||||
.channel(NioServerSocketChannel.class)
|
||||
.childHandler(new ChannelServerInitializer(world, channel));
|
||||
|
||||
this.nettyChannel = bootstrap.bind(port).syncUninterruptibly().channel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() {
|
||||
if (nettyChannel == null) {
|
||||
throw new IllegalStateException("Must start ChannelServer before stopping it");
|
||||
}
|
||||
|
||||
nettyChannel.close().syncUninterruptibly();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user