WebSphere Edge Server - Re: Custom Advisor Commits Suicide Randomly - Why?

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Edge Server > January 2004 > Re: Custom Advisor Commits Suicide Randomly - Why?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: Custom Advisor Commits Suicide Randomly - Why?
Alain Grondin

2004-01-19, 3:02 pm

Hi Jeff,

I have the same problem due to the receive() function that load
only one packet per call. Do you have any advises to load all
the HTTP response. I have cases that need more than 2 calls (receive())
to get all the response. What is the condition to be sure to have
the entire HTTP response ?

Best regards,
Alain

"JLee" <leeja@NOSPAMus.ibm.com> wrote in message
news:3C7FDB60.BC711834@NOSPAMus.ibm.com...
quote:

> Martin,
>
> The caller.receive() and caller.send() APIs will return the number of


bytes
quote:

> successfully received or sent. If the socket times out and you receive


nothing,
quote:

> then the rc is 0. Something else to watch out for is that the receive()


call
quote:

> will receive exactly one packet only. When I worked on the WAS sample


advisor,
quote:

> there were cases where webservers would send the HTTP header in one packet


and
quote:

> the HTTP data in another -- requiring that I do two receive() calls


instead of
quote:

> just one. So the string you're expecting, you may need multiple receive()


calls
quote:

> to get it. If you're seeing the error case frequently, run an iptrace or


snoop
quote:

> or something to see the packets going around and then write the advisor to
> handle the scenarios you see (which is how I found the 2 packet


possibility from
quote:

> the webserver).
>
> Hope that helps...
>
> Jeff
>
>




Dan Poirier

2004-01-19, 3:02 pm

"Alain Grondin" <agrondin@free.fr> writes:
quote:

> Hi Jeff,
>
> I have the same problem due to the receive() function that load
> only one packet per call. Do you have any advises to load all
> the HTTP response. I have cases that need more than 2 calls (receive())
> to get all the response. What is the condition to be sure to have
> the entire HTTP response ?



Usually in socket programming, you want to keep trying to receive data
until you get a 0 return code, indicating the end of the data, or a negative
return code, indicating an error. Something like this (untested):

int iRc;

StringBuffer allData = new StringBuffer();
StringBuffer tmpBuf = new StringBuffer();

while ((iRc = caller.receive(tmpBuf)) > 0) {
allData.append(tmpBuf);
}
if (iRc < 0) {
// error handling
} else {
// process data in allData
}

--
Dan Poirier <poirier@us.ibm.com>
JLee

2004-01-19, 3:02 pm

The while loop should work fine except it may (not sure without testing)
cause a delay while we time out on the last receive that gets no data.
If you know what to look for, you can receive one packet and check for
your target data. If not present, then receive another packet, etc. If
you look at the sample WAS advisor, we have it coded to receive up to
two packets while watching for the HTTP body line we need. You could
model on that or try out the continuous while suggestion.

Jeff

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com