當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。