当前位置: 首页>>代码示例>>Java>>正文


Java Channel.disconnect方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:bitkylin,项目名称:ClusterDeviceControlPlatform,代码行数:13,代码来源:TcpRepository.java

示例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() + ")");
}
 
开发者ID:Superioz,项目名称:MooProject,代码行数:45,代码来源:HandshakeListener.java

示例3: handleError

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void handleError(ErrorMessage error, Channel channel) {
    super.handleError(error, channel);
    channel.disconnect();
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:6,代码来源:BootstrapChannelHandler.java


注:本文中的io.netty.channel.Channel.disconnect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。