my client is c++,not using java,
server acceptor codes fellowing:
public class teste {
public teste()
{
f();
}
void f()
{
try {
InetSocketAddress serverAddress = new
InetSocketAddress(8888);
InetSocketAddress serverAddress1 = new
InetSocketAddress(8008);
DemuxingProtocolCodecFactory dpcf = new
DemuxingProtocolCodecFactory();
dpcf.register(new RoomMessageDecoder());
dpcf.register(new RoomMessageEncoder());
dpcf.register(new CliEntCmdDeconder());
dpcf.register(new CliEntEncoder());
SocketAcceptor acceptor = new
SocketAcceptor(Runtime.getRuntime().availableProcessors() + 1,
Executors.newCachedThreadPool());
SocketAcceptorConfig cfg = new SocketAcceptorConfig();
System.out.println("bloklob"+cfg.getBacklog());
cfg.setBacklog(300);
cfg.setReuseAddress(true);
DefaultIoFilterChainBuilder chain = cfg.getFilterChain();
chain.addLast("logger", new LoggingFilter());
chain.addLast("protocol", new ProtocolCodecFilter(dpcf));
chain.addLast("threadPool", new
ExecutorFilter(Executors.newCachedThreadPool()));
System.out.println("long on ....");
DemuxingIoHandler iohanlder=new DemuxingIoHandler();
iohanlder.addMessageHandler(RoomMessage.class, new
RoomMessageHalder(testb));
iohanlder.addMessageHandler(clicmdbro.class, new
CliEntCmdHandler(testb));
acceptor.bind(serverAddress,iohanlder, cfg);
acceptor.bind(serverAddress1,iohanlder, cfg);
} catch (Exception ex) {
ex.printStackTrace();
}
}
public static void main(String args[]) {
new teste();
}
}
public class RoomMessageDecoder extends MessageDecoderAdapter
{
static int i;
// protected MessageDecoderResult result = NEED_DATA;
/*
* (non-Javadoc)
*
* @see
org.apache.mina.filter.codec.demux.MessageDecoder#decodable(org.apache.mina.common.IoSession,
* org.apache.mina.common.ByteBuffer)
*/
public MessageDecoderResult decodable(IoSession session, ByteBuffer in)
{
if (in.prefixedDataAvailable(2, 1024))
{
// System.out.println("8888 port");
in.getShort();
short com = PrebyteBuffer.getCommand(in);
if (com == (short) 8193)
{
i++;
//System.out.println("before handler:"+i);
return MessageDecoderResult.OK;
} else
return MessageDecoderResult.NOT_OK;
} else
return MessageDecoderResult.NEED_DATA;
}
/*
* (non-Javadoc)
*
* @see
org.apache.mina.filter.codec.demux.MessageDecoder#decode(org.apache.mina.common.IoSession,
* org.apache.mina.common.ByteBuffer,
* org.apache.mina.filter.codec.ProtocolDecoderOutput)
*/
public MessageDecoderResult decode(IoSession session, ByteBuffer in,
ProtocolDecoderOutput out) throws Exception
{
if (in.prefixedDataAvailable(2, 1024))
{
in.getShort();
short com = PrebyteBuffer.getCommand(in);
if (com == (short) 8193)
{//System.out.println("88882 port");
String s = PrebyteBuffer.getString(in);
// System.out.println("String=" + s);
RoomMessage rm = new RoomMessage();
int c=in.getInt();
rm.setId(123456);
out.write(rm);
return MessageDecoderResult.OK;
} else
return MessageDecoderResult.NOT_OK;
} else
return MessageDecoderResult.NEED_DATA;
}
}
public class RoomMessageEncoder implements MessageEncoder {
private static final Set<Class<?>> TYPES;
static {
Set<Class<?>> types = new HashSet<Class<?>>();
types.add(roommEn.class);
TYPES = Collections.unmodifiableSet(types);
}
public void encode(IoSession session, Object message,
ProtocolEncoderOutput out) throws Exception
{
// System.out.println("8888 RoomMessageEncoder...");
roommEn t = (roommEn) message;
ByteBuffer bytebuf = ByteBuffer.allocate(200, false);
bytebuf.setAutoExpand(true);
short length = (short) 0;
String s = t.s;
bytebuf.putShort((short) 0);
PrebyteBuffer.putCommad((short) 123, bytebuf);
length = (short) (length + 13);
PrebyteBuffer.putString(bytebuf, s);
length = (short) (length + s.getBytes().length + 2);
PrebyteBuffer.putLength(bytebuf, length);
bytebuf.flip();
out.write(bytebuf);
}
public Set<Class<?>> getMessageTypes()
{
return TYPES;
}
}
public class RoomMessageHalder implements MessageHandler
{
static int i;
TestB tesb;
public RoomMessageHalder(TestB tesb)
{
this.tesb=tesb;
}
public void messageReceived(IoSession session, Object message)
{
RoomMessage rm = (RoomMessage) message;
roommEn re = new roommEn();
session.getRemoteAddress();
re.s = new String("woshoubule");
InetSocketAddress sa=(InetSocketAddress)
session.getRemoteAddress();
session.write(re);
}
}
Qi wrote:
>
> Hi,
>
> Can you try to print the exception stack trace in the exceptionCaught()
> method of your client-side codes, or attach the source codes of how you
> configure your connector and acceptor?
>
> Cheers,
> Qi
>
>
> chinadeng wrote:
>>
>> thanks your reply very much;
>> It is strongly improve the throughput of the server,when i reset the
>> SocketAcceptorConfig blacklog parameter .
>> The problem is still exst.when 300 clients connect ,10clients will be
>> refused,can not connect successfuly;
>> how can i do it now??
>>
>>
>
>
--
View this message in context:
http://www.nabble.com/How-can-i-improve-the-total-numbers-of-session-which-server-will--handle-connects-from-client-tp14429723s16868p14448174.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.