[xSocket-develop] Data lost using NonBlockingConnection created by NonBlockingConnectionPool in Flu
Status: Inactive
Brought to you by:
grro
|
From: Wu H. <har...@gm...> - 2009-05-05 03:19:46
|
Now I am using XSocket to work for some asynchronous use case. Eg. update
click number of forum article.
But I found that something wrong happened.
I traced the code. Found that if NonBlockingConnection fetched from
NonBlockingConnectionPool and set flushmode to FlushMode.ASYNC,
only partial request can be normally received by server.
I also found some other situation:
1)If NonBlockingConnection fetched by created every time, everything works
well;
2)If NonBlockingConnection fetched from pool, and flushmode set to
FlushMode.ASYNC,
but thread sleep few ms, everything works well;
3)If NonBlockingConnection fetched from pool, and flushmode set to
FlushMode.SYNC,
without thread sleep, everything works well;
It is a bug of XSocket? I am not sure. Can anybody give me some help?
My XSocket Client:
--------------------------------------------------------------------------
public static void testNonBlocking(int index){
INonBlockingConnection connection=null;
try{
//get nonblocking connection
//connection= new NonBlockingConnection("192.169.100.8", 10001);
connection = pool.getNonBlockingConnection("192.169.100.8",
10001);
connection.setAutoflush(false);
connection.setFlushmode(FlushMode.ASYNC);
connection.write(index + " select sql");
connection.write(DELIMITER);
connection.flush();
connection.close();
//sleep 10ms, without sleep, data lost when connection fetched
from pool
//Thread.sleep(10);
}catch(Exception e){
if(connection != null){
try {
pool.destroy(connection);
} catch (IOException e1) {
}
}
e.printStackTrace();
}
}
--------------------------------------------------------------------------------
My XSocket server DataHandler:
--------------------------------------------------------------------------------
public boolean onData(INonBlockingConnection nbc)
throws IOException, BufferUnderflowException,
ClosedChannelException, MaxReadSizeExceededException {
System.out.println("onData");
String data = nbc.readStringByDelimiter(DELIMITER);
System.out.println(data);
String remoteIP = nbc.getRemoteAddress().getHostAddress();
String localIP = nbc.getLocalAddress().getHostAddress();
String remoteHostname = nbc.getRemoteAddress().getHostName();
String localHostname = nbc.getLocalAddress().getHostName();
nbc.write(data + DELIMITER);
return true;
}
public boolean onConnect(INonBlockingConnection connection)
throws IOException, BufferUnderflowException,
MaxReadSizeExceededException {
connection.setAutoflush(false);
connection.setFlushmode(FlushMode.ASYNC);
System.out.println("onConnect");
return false;
}
-------------------------------------------------------------------------------
--
Harry Wu
Cell: +86(0) 13632390992
|