本文整理匯總了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();
}