Apache Mina 1.1.7 と Java 1.6 を使用しています。サーバーは、3 つのメッセージのシーケンスをループでクライアントに送信します。場合によっては、2 つのメッセージ セットが重複することがあります。たとえば、私は期待しています:
++ 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);
}
私は何を間違っていますか?