當前位置: 首頁>>代碼示例>>Java>>正文


Java ChannelHandlerContext.write方法代碼示例

本文整理匯總了Java中io.netty.channel.ChannelHandlerContext.write方法的典型用法代碼示例。如果您正苦於以下問題:Java ChannelHandlerContext.write方法的具體用法?Java ChannelHandlerContext.write怎麽用?Java ChannelHandlerContext.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.channel.ChannelHandlerContext的用法示例。


在下文中一共展示了ChannelHandlerContext.write方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processMessageReceived

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void processMessageReceived(ChannelHandlerContext ctx, RemotingCommand msg) {
    HashMap<String, String> map = msg.getExtFields();
    String key = map.get("action");
    switch (key) {
        case "authorize":
            auth(ctx, msg);
            break;

        case "token":
            token(ctx, msg);
            break;

        case "access":
            access(ctx, msg);
            break;

        default:
            break;
    }
    ctx.write(msg);
}
 
開發者ID:jiumao-org,項目名稱:wechat-mall,代碼行數:23,代碼來源:OAuth2ServerHandler.java

示例2: write

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
    if (msg instanceof FMLProxyPacket)
    {
        if (side == Side.CLIENT)
        {
            //Client to server large packets are not supported to prevent client being bad.
            ctx.write(((FMLProxyPacket) msg).toC17Packet(), promise);
        }
        else
        {
            List<Packet<INetHandlerPlayClient>> parts = ((FMLProxyPacket)msg).toS3FPackets();
            for (Packet<INetHandlerPlayClient> pkt : parts)
            {
                ctx.write(pkt, promise);
            }
        }
    }
    else
    {
        ctx.write(msg, promise);
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:25,代碼來源:NetworkDispatcher.java

示例3: writeMessageToChannel

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
private void writeMessageToChannel ( final ChannelHandlerContext ctx, final ByteBuf data, final ChannelPromise promise )
{
    final int seq = this.ackBuffer.addMessage ( data );

    if ( promise == null )
    {
        ctx.write ( new InformationTransfer ( seq, this.receiveCounter, data ) );
    }
    else
    {
        ctx.write ( new InformationTransfer ( seq, this.receiveCounter, data ), promise );
    }

    logger.trace ( "Enqueued message as {} : {}", seq, data );

    // we can stop timer #2 here ... will be restarted by receive
    this.timer2.stop ();
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:19,代碼來源:MessageChannel.java

示例4: write

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void write ( final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise ) throws Exception
{
    if ( msg instanceof OpenResponse )
    {
        writeOpenResponse ( ctx, (OpenResponse)msg, promise );
    }
    else if ( msg instanceof SyslogResponse )
    {
        writeGenericResponse ( ctx, (AbstractGenericResponse)msg, promise );
    }
    else if ( msg instanceof ServerCloseMessage )
    {
        ctx.write ( new Frame ( 0, "serverclose", (ByteBuf)null ) );
    }
    else
    {
        super.write ( ctx, msg, promise );
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:21,代碼來源:FrameProcessor.java

示例5: sendHandshakeOptionHagglingReply

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
private void sendHandshakeOptionHagglingReply(ChannelHandlerContext ctx, int option, int error, ByteBuf data) throws IOException {
    ByteBuf optionReply = ctx.alloc().buffer(18);
    optionReply.writeLong(Protocol.HANDSHAKE_REPLY_MAGIC);
    optionReply.writeInt(option);
    optionReply.writeInt(error); // aka. reply type
    int len = 0;
    if (data != null)
        len = data.readableBytes();
    optionReply.writeInt(len);
    ctx.write(optionReply);
    if (data != null)
        ctx.write(data);
}
 
開發者ID:MineboxOS,項目名稱:tools,代碼行數:14,代碼來源:HandshakePhase.java

示例6: write

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void write ( final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise ) throws Exception
{
    logger.trace ( "Write {}", msg );
    synchronized ( this )
    {
        if ( msg instanceof DataTransmissionMessage )
        {
            switch ( (DataTransmissionMessage)msg )
            {
                case REQUEST_START:
                    ctx.write ( new UnnumberedControl ( Function.STARTDT_ACT ), promise );
                    break;
                case CONFIRM_START:
                    ctx.write ( new UnnumberedControl ( Function.STARTDT_CONFIRM ), promise );
                    break;
                case REQUEST_STOP:
                    ctx.write ( new UnnumberedControl ( Function.STOPDT_ACT ), promise );
                    break;
                case CONFIRM_STOP:
                    ctx.write ( new UnnumberedControl ( Function.STOPDT_CONFIRM ), promise );
                    break;
                default:
                    throw new EncoderException ( String.format ( "Unknown data transmission message: %s", msg ) );
            }
        }
        else if ( msg == MessageSource.NOTIFY_TOKEN )
        {
            handleMessageSourceUpdates ( ctx );
        }
        else
        {
            handleMessageWrite ( ctx, msg, promise );
        }
    }
}
 
開發者ID:eclipse,項目名稱:neoscada,代碼行數:37,代碼來源:MessageChannel.java

示例7: channelRead0

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void channelRead0(ChannelHandlerContext ctx,
		SocksRequest socksRequest) throws Exception {
	switch (socksRequest.requestType()) {
	case INIT: {
		logger.info("localserver init");
		ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
		ctx.write(new SocksInitResponse(SocksAuthScheme.NO_AUTH));
		break;
	}
	case AUTH:
		ctx.pipeline().addFirst(new SocksCmdRequestDecoder());
		ctx.write(new SocksAuthResponse(SocksAuthStatus.SUCCESS));
		break;
	case CMD:
		SocksCmdRequest req = (SocksCmdRequest) socksRequest;
		if (req.cmdType() == SocksCmdType.CONNECT) {
			logger.info("localserver connect");
			ctx.pipeline().addLast(new SocksServerConnectHandler(config));
			ctx.pipeline().remove(this);
			ctx.fireChannelRead(socksRequest);
		} else {
			ctx.close();
		}
		break;
	case UNKNOWN:
		ctx.close();
		break;
	}
}
 
開發者ID:breakEval13,項目名稱:NSS,代碼行數:31,代碼來源:SocksServerHandler.java

示例8: write

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
    if (msg instanceof AmqpDeliverMessage) {
        ((AmqpDeliverMessage) msg).write(ctx);
    } else  {
        ctx.write(msg, promise);
    }
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:9,代碼來源:AmqpMessageWriter.java

示例9: channelRead

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx,
    Object msg) {
    ByteBuf in = (ByteBuf) msg;
    System.out.println("Server received: " + in.toString(CharsetUtil.UTF_8));
    ctx.write(in);
}
 
開發者ID:zy416548283,項目名稱:NettyStudy,代碼行數:8,代碼來源:EchoServerHandler.java

示例10: write

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void write(ChannelHandlerContext ctx, Object message, ChannelPromise promise)
        throws Exception
{
    if (message instanceof ThriftRequest) {
        ThriftRequest thriftRequest = (ThriftRequest) message;
        sendMessage(ctx, thriftRequest, promise);
    }
    else {
        ctx.write(message, promise);
    }
}
 
開發者ID:airlift,項目名稱:drift,代碼行數:13,代碼來源:ThriftClientHandler.java

示例11: handleMessage

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void handleMessage(ChannelHandlerContext ctx, HandshakeRequest msg) {
	ClientMessage message = ClientMessage.SUCCESSFUL_CONNECTION;
	if (msg.getVersion() != Quavo.VERSION) {
		message = ClientMessage.OUT_OF_DATE;
	}

	ctx.write(new HandshakeResponse(message));
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:10,代碼來源:HandshakeListener.java

示例12: handleException

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
private void handleException(ChannelHandlerContext ctx, Exception e) {
    if (e instanceof UnauthorizedException) {
        ctx.write(Response.buildDefaultFullHttpResponse(HttpResponseStatus.UNAUTHORIZED));
    }
    else if (e instanceof ForbiddenException) {
        ctx.write(Response.buildDefaultFullHttpResponse(HttpResponseStatus.FORBIDDEN));
    }
    else {
        ctx.write(Response.buildDefaultFullHttpResponse(HttpResponseStatus.INTERNAL_SERVER_ERROR));
    }
}
 
開發者ID:zhyzhyzhy,項目名稱:Ink,代碼行數:12,代碼來源:HttpRequestHandler.java

示例13: write

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (msg instanceof Heartbeat) {
        ctx.write(msg, promise);
    } else {
        super.write(ctx, msg, promise);
    }
}
 
開發者ID:hekate-io,項目名稱:hekate,代碼行數:9,代碼來源:NettyClientIdleStateHandler.java

示例14: write

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception
{
    if (!(msg instanceof FMLProxyPacket))
    {
        return;
    }
    FMLProxyPacket pkt = (FMLProxyPacket) msg;
    OutboundTarget outboundTarget;
    Object args = null;
    NetworkDispatcher dispatcher = ctx.channel().attr(NetworkDispatcher.FML_DISPATCHER).get();
    // INTERNAL message callback - let it pass out
    if (dispatcher != null)
    {
        ctx.write(msg, promise);
        return;
    }

    outboundTarget = ctx.channel().attr(FML_MESSAGETARGET).get();
    Side channelSide = ctx.channel().attr(NetworkRegistry.CHANNEL_SOURCE).get();
    if (outboundTarget != null && outboundTarget.allowed.contains(channelSide))
    {
        args = ctx.channel().attr(FML_MESSAGETARGETARGS).get();
        outboundTarget.validateArgs(args);
    }
    else if (channelSide == Side.CLIENT)
    {
        outboundTarget = OutboundTarget.TOSERVER;
    }
    else
    {
        throw new FMLNetworkException("Packet arrived at the outbound handler without a valid target!");
    }

    List<NetworkDispatcher> dispatchers = outboundTarget.selectNetworks(args, ctx, pkt);

    // This will drop the messages into the output queue at the embedded channel
    if (dispatchers == null)
    {
        ctx.write(msg, promise);
        return;
    }
    for (NetworkDispatcher targetDispatcher : dispatchers)
    {
        targetDispatcher.sendProxy((FMLProxyPacket) msg);
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:48,代碼來源:FMLOutboundHandler.java

示例15: handleMessage

import io.netty.channel.ChannelHandlerContext; //導入方法依賴的package包/類
@Override
public void handleMessage(ChannelHandlerContext ctx, XOREncryptionRequest msg) {
	ctx.write(new XOREncryptionResponse(msg.getKey()));
}
 
開發者ID:jordanabrahambaws,項目名稱:Quavo,代碼行數:5,代碼來源:XOREncryptionListener.java


注:本文中的io.netty.channel.ChannelHandlerContext.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。