Netty Flash XmlSocket消息接收错误

时间:2012-06-06 16:29:34

标签: flash netty xmlsocket

我正在netty中创建自己的flash游戏服务器。我在端口843中使用闪存策略服务器,在8080中使用游戏服务器端口...另外,我正在使用zerodelimeter进行成帧器;但是,当我在Flash客户端上接收消息时,我收到两条消息而不是一条消息。第一条消息是我应该获得的真实信息;但是,第二个是空消息。如何避免在网络端接收第二条消息?

谢谢,

在下面,您可以查看我的ChannelPipelineFactory ...

    public class SocketServerPipelineFactory implements ChannelPipelineFactory {

    public ChannelPipeline getPipeline() throws Exception {
        PlayerController controller = PlayerController.createPlayerController();

        ChannelPipeline pipeline = Channels.pipeline();

        pipeline.addLast("framer", new DelimiterBasedFrameDecoder(8192,
                zeroDelimiter()));
        pipeline.addLast("decoder", new StringDecoder(CharsetUtil.UTF_8));
        pipeline.addLast("encoder", new StringEncoder(CharsetUtil.UTF_8));

        pipeline.addLast("handler", new SocketServerHandler(controller));

        return pipeline;
    }

    public static ChannelBuffer[] zeroDelimiter() {
        return new ChannelBuffer[] { ChannelBuffers.wrappedBuffer(new byte[] { '\0' }),
                ChannelBuffers.wrappedBuffer(new byte[] { '\r', '\n' }) };
    }

}

1 个答案:

答案 0 :(得分:0)

我认为您应该使用nul delimiter而不是0.这是netty game server,它提供Flash策略文件。 policy server运行在843.下面粘贴的是相关的弹簧配置,这里是policy file decoder以供参考。

<!-- Configure the Flash policy server. By default it runs at 843 -->
<bean id="flashPolicyServer" class="org.menacheri.jetserver.server.netty.FlashPolicyServer"
    init-method="createServerBootstrap" destroy-method="stopServer">
    <property name="pipelineFactory" ref="flashPolicyServerPipelineFactory"></property>
    <property name="gameAdminService" ref="gameAdminService"></property>
    <property name="portNumber" value="${flash.policy.port}"></property>
</bean>

<!-- All the pipeline factory beans are now defined -->
<bean id="flashPolicyServerPipelineFactory" class="org.menacheri.jetserver.server.netty.FlashPolicyServerPipelineFactory">
    <lookup-method name="getFlashPolicyServerHandler" bean="flashPolicyServerHandler"/>
    <property name="timer" ref="hashedWheelTimer"></property>
</bean>