1
我使用Apache 1.1.7米娜和Java 1.6。服务器循环发送三个消息序列给客户端。有时两组消息重叠。例如,我期待:麻烦同步线程与Apache米娜
++ recv: MSGHEAD
++ recv: message body 1
++ recv: .
++ recv: MSGHEAD
++ recv: message body 2
++ recv: .
,但我得到这个代替:
++ recv: MSGHEAD
++ recv: MSGHEAD
++ recv: message body 1
++ recv: .
++ recv: message body 2
++ recv: .
这里是我的服务器配置:
SocketAcceptor acceptor = new SocketAcceptor();
SocketAcceptorConfig config = new SocketAcceptorConfig();
config.setThreadModel(ThreadModel.MANUAL);
if (true) {
SSLContextFactory factory = new SSLContextFactory();
config.getFilterChain().addLast("sslFilter", new SSLFilter(factory.getInstance(true)));
}
System.out.println(config.getFilterChain().toString());
config.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName("UTF-8"))));
config.getFilterChain().addLast("to-message", new ToMessageIoFilter());
config.getSessionConfig().setReuseAddress(true);
config.getSessionConfig().setTcpNoDelay(true);
acceptor.bind(new InetSocketAddress(PORT), new MinaServerHandler(new MinaConnectionFactory()), config);
}
这里是我发出的一系列消息:
public void sendMessage(String msg) throws IOException {
synchronized(session){
writeLine("MSGHEAD");
writeLine(msg);
writeLine(".");
}
}
private void writeLine(String line) {
WriteFuture w=session.write(line);
}
我是什么d错了吗?