本文整理汇总了Java中io.netty.channel.Channel.disconnect方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.disconnect方法的具体用法?Java Channel.disconnect怎么用?Java Channel.disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.channel.Channel
的用法示例。
在下文中一共展示了Channel.disconnect方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: manualRemoveChannel
import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
* 手动移除相应的 Channel
*
* @param channel 欲被手动移除的 Channel
*/
private void manualRemoveChannel(Channel channel) {
if (channel.isActive()) {
channel.disconnect();
} else {
removeChannelCompleted(channel);
}
}
示例2: onHandshake
import io.netty.channel.Channel; //导入方法依赖的package包/类
@EventHandler
public void onHandshake(HandshakeEvent event) {
Channel channel = event.getChannel();
PacketHandshake packet = event.getPacket();
String header = "auth";
String version = Cloud.getInstance().getVersion();
InetSocketAddress remoteAddress = (InetSocketAddress) channel.remoteAddress();
// checks if address is allowed by the whitelist
if(!Cloud.getInstance().getServer().getWhitelist().allowed(remoteAddress)) {
packet.respond(new PacketRespond(header, version, ResponseStatus.FORBIDDEN));
channel.disconnect();
}
// checks if the instance name is valid
if(!Validation.INSTANCE_NAME.matches(packet.identifier)) {
packet.respond(new PacketRespond(header, version, ResponseStatus.BAD_REQUEST));
channel.disconnect();
return;
}
// checks if already a daemon from this host connected to the server
if(packet.type == ClientType.DAEMON && Cloud.getInstance().getClientManager().contains(remoteAddress)) {
packet.respond(new PacketRespond(header, version, ResponseStatus.FORBIDDEN));
channel.disconnect();
return;
}
//.
packet.respond(new PacketRespond(header, version, ResponseStatus.OK));
// Add client
MooClient client = new MooClient(packet.identifier,
remoteAddress.getAddress().getHostAddress(),
remoteAddress.getPort(), packet.subPort, packet.type, channel);
client.setId(Cloud.getInstance().getClientManager().add(client));
// fire event of client connection
EventExecutor.getInstance().execute(new MooClientConnectedEvent(client));
Cloud.getInstance().getLogger().debug(ConsoleColor.GREEN.toString()
+ client.getType() + " client connected @(" + remoteAddress.getAddress().getHostAddress() + ")");
}
示例3: handleError
import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void handleError(ErrorMessage error, Channel channel) {
super.handleError(error, channel);
channel.disconnect();
}