Delay In Reading data from Nonblocking Socket - URGENT
843790Oct 25 2006 — edited Nov 11 2006Hi all,
Can anyone give some advices on my problem..?
I have developed a cimd client application. I am using
Nonblocking sockets (java.nio) SocketChannel class..I am opening connection to the server with the nonblocking socket channel.I have a problem in reading data from the socket. There is some delay in capturing the message at the application level from the tcp layer.The ethereal traces shows that the packet comes at the tcp layer but the Socket in the application is picking up the packet after few milli seconds (say 300 milli seconds) which is very high for my kind of applications.
There is no sleep in the Reading thread.I am not able to understand whether the problem is in reading data from the socket or at the network level..
SocketChannel client= null;
ByteBuffer readbuffer= null;
CharsetDecoder decoder = null;
Charset charset =null;
radbuffer = ByteBuffer.allocate(1024);
charset = Charset.forName( "us-ascii" );
decoder = charset.newDecoder();
..................................
public String readLine()
{
String line;
try
{
if(client.read(readbuffer) == -1)
{
debug("Connection is lost with the Server "+smscip,LOG_SOCKET);
loginsuccess = false;
reopen();
return null;
}
readbuffer.flip();
charBuffer = decoder.decode( readbuffer );
line = charBuffer.toString();
// line = line.trim();
readbuffer.flip();
readbuffer.clear();
return line;
}
catch(Exception e)
{
debug("Exception in readLine: "+e,LOG_SOCKET);
//bconnect =false;
reopen();
return null;
}
}
.........................
Can anyone please help me in solving this problem....Suggest me how to reduce this delay in reading data from the socket........
Thanks in Advance...
Venkatesh