Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 核心游戏逻辑循环将数据发送到Netty中的通道_Java_Unity3d_Networking_Netty_Game Loop - Fatal编程技术网

Java 核心游戏逻辑循环将数据发送到Netty中的通道

Java 核心游戏逻辑循环将数据发送到Netty中的通道,java,unity3d,networking,netty,game-loop,Java,Unity3d,Networking,Netty,Game Loop,我想每100毫秒向所有通道发送一次世界状态。但它只会打一次电话 我的代码: public class IncomeMessageTcpHandler extends SimpleChannelInboundHandler<byte[]> { @Override public void channelActive(ChannelHandlerContext ctx) throws Exception { Channel channel = ct

我想每100毫秒向所有通道发送一次世界状态。但它只会打一次电话

我的代码:

        public class IncomeMessageTcpHandler extends SimpleChannelInboundHandler<byte[]> {

@Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {
        Channel channel = ctx.channel();

        channel.eventLoop().scheduleAtFixedRate(new Runnable() {
            @Override
            public void run() {
                System.out.println("send");
                channel.writeAndFlush(GameLogic.Instance.flushMessageData());
            }
        }, 100, 100, TimeUnit.MILLISECONDS);
    }
}
公共类IncomeMessageCpHandler扩展了SimpleChannelInboundHandler{
@凌驾
公共无效channelActive(ChannelHandlerContext ctx)引发异常{
Channel=ctx.Channel();
channel.eventLoop().scheduleAtFixedRate(新的Runnable()){
@凌驾
公开募捐{
System.out.println(“发送”);
channel.writeAndFlush(GameLogic.Instance.flushMessageData());
}
},100100,时间单位为毫秒);
}
}
现在该方法只调用一次。 我使用的是4.1.13.Final

    public class UnityServerTcpChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    public void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline p = ch.pipeline();

        p.addLast("frameDecoder", new FixedLengthFrameDecoder(6));
        p.addLast("bytesDecoder", new ByteArrayDecoder());

        p.addLast("bytesEncoder", new ByteArrayEncoder());

        p.addLast(new IncomeMessageTcpHandler());
    }
}
公共类UnityServerTcpChannelInitializer扩展了ChannelInitializer{
@凌驾
public void initChannel(SocketChannel ch)引发异常{
ChannelPipeline p=通道管道();
p、 addLast(“帧解码器”,新的固定长度帧解码器(6));
p、 addLast(“bytesDecoder”,新的ByteArrayCoder());
p、 addLast(“bytesEncoder”,新的ByteArrayEncoder());
p、 addLast(新incomeMessageCpHandler());
}
}
当我注释channel.writeAndFlush(GameLogic.Instance.flushMessageData())时;每100毫秒运行一次任务。。。是我的错。 我的方法GameLogic.Instance.flushMessageData()生成NullPointerException,但我不知道Runnable不会引发任何异常。 这就是为什么它在没有任何警告的情况下停止运行