Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Socket Write Issue  RSS feed

 
Kiran Kadambi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am listening on a socket(S1) at one side and have created multiple instances of another socket(S2), to simulate concurrent users, using which i write data. The problem now is that S2 is writing too fast to S1 and flushing the data even before S1 can read. They are on high capacity machines. Since S1 cannot get the request, it cannot proceed and throws an error. S1 is not being swamped as it has enough resources and threads pooled to handle such conditions. This is totally baffelling me as i tried all the tricks mentioned.

I would really appritiate your input on this.

Regards
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should share the exception and stack trace with us, not to mention relevant code snippets. It sounds like S2 is closing the socket while S1 is still reading it. In any case, this is a networking question rather than an IO question, so let's move it to the Sockets and Internet Protocols forum.
 
Kiran Kadambi
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is S2:
for(int i=0;i<noOfReqs;i++) {
os.write(requestString[i].getBytes());
os.flush();
data = new StringBuffer();
charIn = -1;
while((charIn = dis.read()) != -1) {
if (charIn== BEL_CHAR)
break;
data.append((char)charIn);
}
connDelayError = connDelay;
if(compare == 1) {
if (data.toString().equalsIgnoreCase(resp[i])) {
System.out.println("Correct Response::::::::::::::::");
}else {
System.out.println("Wrong Response::::::::::::::::"+data.toString()+"===");
break;
}
}
if(reqDelay > 0)
sleep(reqDelay);
}//End of for loop.

Here is S1


do
{
try
{
LogHandler.log(LogHandler.LOG_INFORMATION,this,"handleConnection()", "Request Received Time:"+System.currentTimeMillis());
charIn = -1;
while((charIn = input.read()) != -1)
{

if ((char)charIn== '~')
break;
docString.append((char)charIn);
}

docString.append("\n");
}
catch( InterruptedIOException ioe )
{
if (System.currentTimeMillis() - lStartTime > m_MaxInactiveTime * 1000)
{
clientSocket.close();
return;
}
}


iLen = docString.toString().trim().length();
if (iLen != 0)
{
lStartTime = System.currentTimeMillis();
}
} while(iLen == 0);


The exception is a socket closed exception.

Thanks
Kiran
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Would you please edit your post and surround your code with code-tags?

like that, without the blanks:

[ September 28, 2004: Message edited by: Stefan Wagner ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!