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


Java Channel.writeAndFlush方法代码示例

本文整理汇总了Java中io.netty.channel.Channel.writeAndFlush方法的典型用法代码示例。如果您正苦于以下问题:Java Channel.writeAndFlush方法的具体用法?Java Channel.writeAndFlush怎么用?Java Channel.writeAndFlush使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在io.netty.channel.Channel的用法示例。


在下文中一共展示了Channel.writeAndFlush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: broadcastMess

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * 广播普通消息
 *
 * @param message
 */
public static void broadcastMess(int uid, String nick, String message) {
    if (!BlankUtil.isBlank(message)) {
        try {
            rwLock.readLock().lock();
            Set<Channel> keySet = userInfos.keySet();
            for (Channel ch : keySet) {
                UserInfo userInfo = userInfos.get(ch);
                if (userInfo == null || !userInfo.isAuth()) continue;
                ch.writeAndFlush(new TextWebSocketFrame(ChatProto.buildMessProto(uid, nick, message)));
            }
        } finally {
            rwLock.readLock().unlock();
        }
    }
}
 
开发者ID:beyondfengyu,项目名称:HappyChat,代码行数:21,代码来源:UserInfoManager.java

示例2: handshake

import io.netty.channel.Channel; //导入方法依赖的package包/类
protected void handshake(HelloMessage request, Channel channel) {
    try {
        switch (getAuthScheme()) {
            case CHALLENGE_RESPONSE:
                handshakeChallengeResponse(request, channel);
                break;
            case NO_AUTH:
                // shouldn't get here
                break;
        }
    } catch (AuthException e) {
        logger.warn("[{}->{}] Failed to authenticate connection: {}",
                    new Object[]{getLocalNodeIdString(), 
                                 getRemoteNodeIdString(), 
                                 e.getMessage()});
        channel.writeAndFlush(getError(request.getHeader().getTransactionId(), 
                               e, MessageType.HELLO));
        channel.close();
    }
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:21,代码来源:AbstractRPCChannelHandler.java

示例3: userEventTriggered

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
    Channel channel = ctx.channel();
    if (IdleStateEvent.class.isAssignableFrom(evt.getClass())) {
        IdleStateEvent event = (IdleStateEvent) evt;
        if (event.state() == IdleState.ALL_IDLE) {
            //发送心跳
            channel.writeAndFlush(PING);
        }
        if (event.state() == IdleState.READER_IDLE) {
            //发送心跳
            channel.writeAndFlush(PING);
        }
        if (event.state() == IdleState.WRITER_IDLE) {
            channel.writeAndFlush(PING);
        }
    } else {
        super.userEventTriggered(ctx, evt);
    }
}
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:21,代码来源:NodeChannelInBoundHandler.java

示例4: CloudNetClient

import io.netty.channel.Channel; //导入方法依赖的package包/类
public CloudNetClient(INetworkComponent iNetworkComponent, Channel channel)
{
    this.networkComponent = iNetworkComponent;
    this.networkComponent.setChannel(channel);
    this.channel = channel;

    System.out.println("Channel connected [" + channel.remoteAddress().toString() + "/serverId=" + networkComponent.getServerId() + "]");

    if(networkComponent instanceof Wrapper)
    {
        StatisticManager.getInstance().wrapperConnections();
        System.out.println("Wrapper [" + networkComponent.getServerId() + "] is connected.");
        CloudNet.getInstance().getEventManager().callEvent(new WrapperChannelInitEvent((Wrapper) networkComponent, channel));
        CloudNet.getInstance().getDbHandlers().getWrapperSessionDatabase().addSession(new WrapperSession(UUID.randomUUID(), ((Wrapper)networkComponent).getNetworkInfo(), System.currentTimeMillis()));
        ((Wrapper)networkComponent).updateWrapper();
    }

    CloudNetwork cloudNetwork = CloudNet.getInstance().getNetworkManager().newCloudNetwork();
    channel.writeAndFlush(new PacketOutCloudNetwork(cloudNetwork));

    if(networkComponent instanceof MinecraftServer)
    {
        ((MinecraftServer)networkComponent).setChannelLostTime(0L);
        networkComponent.getWrapper().sendPacket(new PacketOutOnlineServer(((MinecraftServer)networkComponent).getServerInfo()));
    }
    if(networkComponent instanceof ProxyServer)
    {
        ((ProxyServer)networkComponent).setChannelLostTime(0L);
    }
    CloudNet.getInstance().getEventManager().callEvent(new ChannelInitEvent(channel, networkComponent));
    init(cloudNetwork);
}
 
开发者ID:Dytanic,项目名称:CloudNet,代码行数:33,代码来源:CloudNetClient.java

示例5: handleSyncOffer

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
protected void handleSyncOffer(SyncOfferMessage request,
                               Channel channel) {
    try {
        String storeName = request.getStore().getStoreName();

        SyncRequestMessage srm = new SyncRequestMessage();
        AsyncMessageHeader header = new AsyncMessageHeader();
        header.setTransactionId(request.getHeader().getTransactionId());
        srm.setHeader(header);
        srm.setStore(request.getStore());

        for (KeyedVersions kv : request.getVersions()) {
            Iterable<org.sdnplatform.sync.thrift.VectorClock> tvci =
                    kv.getVersions();
            Iterable<VectorClock> vci = new TVersionIterable(tvci);

            boolean wantKey = syncManager.handleSyncOffer(storeName,
                                                          kv.getKey(), vci);
            if (wantKey)
                srm.addToKeys(kv.bufferForKey());
        }

        SyncMessage bsm =
                new SyncMessage(MessageType.SYNC_REQUEST);
        bsm.setSyncRequest(srm);
        if (logger.isTraceEnabled()) {
            logger.trace("[{}->{}] Sending SyncRequest with {} elements",
                         new Object[]{getLocalNodeIdString(),
                                      getRemoteNodeIdString(),
                                      srm.getKeysSize()});
        }
        channel.writeAndFlush(bsm);

    } catch (Exception e) {
        channel.writeAndFlush(getError(request.getHeader().getTransactionId(),
                               e, MessageType.SYNC_OFFER));
    }
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:40,代码来源:RPCChannelHandler.java

示例6: action

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void action(Channel ch, Proto proto) throws Exception {
    // write heartbeat reply
    proto.setOperation(Constants.OP_HEARTBEAT_REPLY);
    proto.setBody(null);
    ch.writeAndFlush(proto);
}
 
开发者ID:onsoul,项目名称:os,代码行数:8,代码来源:HeartbeatOperation.java

示例7: call

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void call(ChannelHandlerContext ctx, Ping message) {
    Channel channel = ctx.channel();
    channel.writeAndFlush(PONG);
    saveLiveDc(channel);
    log.debug("node send pong to data center, channel:{}", ctx.channel());
}
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:8,代码来源:NodePingHandler.java

示例8: sendRemote

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * 给remoteserver发送数据--需要进行加密处理
 * 
 * @param data
 * @param length
 * @param channel
 */
public void sendRemote(byte[] data, int length, Channel channel) {
	if(isProxy) {
		_crypt.encrypt(data, length, _remoteOutStream);
		data = _remoteOutStream.toByteArray();
	}
	channel.writeAndFlush(Unpooled.wrappedBuffer(data));
	logger.debug("sendRemote message:isProxy = " + isProxy +",length = " + length+",channel = " + channel);
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:16,代码来源:SocksServerConnectHandler.java

示例9: broadPing

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * 心跳检测Ping
 */
public void broadPing(){
    try{
        rwLock.readLock().lock();
        logger.info("broadCastPing userCount: {}", userCount.intValue());
        Set<Channel> keySet = chatUserMap.keySet();
        for (Channel ch : keySet) {
            ChatUser cUser = chatUserMap.get(ch);
            if (cUser == null || !cUser.isAuth()) continue;
            ch.writeAndFlush(new TextWebSocketFrame(QuarkChatProtocol.buildPing()));
        }
    }finally {
        rwLock.readLock().unlock();
    }
}
 
开发者ID:ChinaLHR,项目名称:JavaQuarkBBS,代码行数:18,代码来源:ChannelManager.java

示例10: send

import io.netty.channel.Channel; //导入方法依赖的package包/类
public static void send( Channel ctx, final byte[] data) {
    if (ctx == null)
        return;
    final ByteBuf byteBufMsg = ctx.alloc().buffer(data.length);
    byteBufMsg.writeBytes(data);
    ctx.writeAndFlush(byteBufMsg);
}
 
开发者ID:1991wangliang,项目名称:sds,代码行数:8,代码来源:SocketUtils.java

示例11: send

import io.netty.channel.Channel; //导入方法依赖的package包/类
public static void send(final Channel ctx, final byte[] data) {
    if (ctx == null)
        return;
    final ByteBuf byteBufMsg = ctx.alloc().buffer(data.length);
    byteBufMsg.writeBytes(data);
    ctx.writeAndFlush(byteBufMsg);
}
 
开发者ID:1991wangliang,项目名称:sds,代码行数:8,代码来源:SocketUtils.java

示例12: sentToClient

import io.netty.channel.Channel; //导入方法依赖的package包/类
private void sentToClient(RemotingCommand request){
	Map<String,Set<Channel>> groupChannelTable = this.producerManager.getGroupChannelTable();
	if(groupChannelTable.get(request.getGroup()) == null || 
			CollectionUtils.isEmpty(groupChannelTable.get(request.getGroup()))){
		return;
	}
	List<Channel> channels = Lists.newArrayList(groupChannelTable.get(request.getGroup()));
	Channel c = channels.get(new Random().nextInt(channels.size()));
	if(c.isActive()){
		c.writeAndFlush(request);
	}
}
 
开发者ID:yanghuijava,项目名称:elephant,代码行数:13,代码来源:TransactionCheckJob.java

示例13: unexpectedMessage

import io.netty.channel.Channel; //导入方法依赖的package包/类
/**
 * Send an error to the channel indicating that we got an unexpected
 * message for this type of RPC client
 * @param transactionId the transaction ID for the message that generated
 * the error
 * @param type The type of the message that generated the error
 * @param channel the channel to write the error
 */
protected void unexpectedMessage(int transactionId,
                                 MessageType type,
                                 Channel channel) {
    String message = "Received unexpected message: " + type;
    logger.warn("[{}->{}] {}",
                new Object[]{getLocalNodeIdString(), 
                             getRemoteNodeIdString(),
                             message});
    channel.writeAndFlush(getError(transactionId, 
                           new SyncException(message), type));
}
 
开发者ID:xuraylei,项目名称:fresco_floodlight,代码行数:20,代码来源:AbstractRPCChannelHandler.java

示例14: call

import io.netty.channel.Channel; //导入方法依赖的package包/类
@Override
public void call(ChannelHandlerContext ctx, NodeInfoReq message) {
    Channel channel = ctx.channel();
    channel.writeAndFlush(NodeInfoResp.builder().result(NodeMessageEnum.OK.getCode()).build().encode());
    log.debug("receive nodeInfoReq,channel:{}", channel);
}
 
开发者ID:lee123lee123,项目名称:GoPush,代码行数:7,代码来源:NodeInfoHandler.java

示例15: sendPong

import io.netty.channel.Channel; //导入方法依赖的package包/类
public static void sendPong(Channel channel) {
    channel.writeAndFlush(new TextWebSocketFrame(ChatProto.buildPongProto()));
}
 
开发者ID:beyondfengyu,项目名称:HappyChat,代码行数:4,代码来源:UserInfoManager.java


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