本文整理汇总了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);
}
示例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);
}
}
示例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 ();
}
示例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 );
}
}
示例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);
}
示例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 );
}
}
}
示例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;
}
}
示例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);
}
}
示例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);
}
示例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);
}
}
示例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));
}
示例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));
}
}
示例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);
}
}
示例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);
}
}
示例15: handleMessage
import io.netty.channel.ChannelHandlerContext; //导入方法依赖的package包/类
@Override
public void handleMessage(ChannelHandlerContext ctx, XOREncryptionRequest msg) {
ctx.write(new XOREncryptionResponse(msg.getKey()));
}