Re: Repeated read From Socket is Truncated



Trouble@Mill wrote:

It's
just that Java doesn't recognize when that response is complete, and
to return control back to the client code.

As Eric already pointed out other languages are not able to do
that, either.

Quite the opposite. I'd say that a protocol that relies on "data
content" to know when a transmission is complete is the poorly
designed one. The socket protocol, for TCP, *DOES* know when the
transmission is complete, and *DOES* signal that to the client.

As Eric already pointed out ...
There is just one point where you might be right. If the whole
message fits into one TCP-packet (AFAIR something up to 55 KB)
your point of view can be right.

But since the days of X.25 over ISDN I never saw a protocol
(e.g. OFTP) again that relies on that. Even these kind of
protocols don't use single packets for transfering "X.25-packets"
over TCP/IP but wrap around an own packet (e.g. OFTP over TCP/IP)

It
works perfectly in C using recv().

Maybe the size of the response is fixed (recv() reads in data
up to a specified length - like inputstream.read(byte[], off, len))
so you should initialize cBuf with that size and read until the
buffer is full.

That continues to receive data,
until the complete message has been accepted, and then it signals
completion, so the code can then process what it's just recieved. Why
can't Java do that.

If the fixed-size-theory is correct the code should look like this:

byte[] buf = new byte[bufferSize];
int readSum = 0;
int read;
while (readSum < buf.length && (read = input.read(buf, readSum, buf.length - readSum)) != -1){
readSum += read;
}
xml.parseV(new String(buf, 0, readSum, encoding));

You can't use a Reader, because TCP/IP is byte-based so a
fixed data-size will always be specified in bytes, that
isn't necesserily the base of the encoding being used (e.g. UTF-8)

If that isn't working, either, you should organize the source
of the mentioned C-program that is working. Maybe it's possible
to find out the difference between that implementation and yours.


Regards, Lothar
--
Lothar Kimmeringer E-Mail: spamfang@xxxxxxxxxxxxxx
PGP-encrypted mails preferred (Key-ID: 0x8BC3CD81)

Always remember: The answer is forty-two, there can only be wrong
questions!
.



Relevant Pages

  • Re: IE error when closing
    ... Don, thanks for the response. ... Adobe and Java which both work with IE on certain sites. ... >> found more then one post who never had the issue until they got SP2. ...
    (microsoft.public.windows.inetexplorer.ie6.browser)
  • C# generated .NET stubs break on a null return of a complex object
    ... I have a SOAP written in Java, and being served by Apache Axis - using the ... When I make this same call with my java client - here is the SOAP message ... the response object is basically empty - because there were ...
    (microsoft.public.dotnet.framework.webservices)
  • Re: Confirm my Performance Test Against Java?
    ... language choice or even hardware. ... I often hear that Ruby is "fast enough" or that the performance ... a java environment my team has built provides SOAP/REST ... our average server side response time is something we ...
    (comp.lang.ruby)
  • Re: Java beginners and GUIs (was Re: simple sound problem)
    ... > perspective of learning and understanding Java, ... When I wrote that I didn't see a reason why it ... married to any single pedagogy for teaching Java. ... > section of Andrew's response would have appeared. ...
    (comp.lang.java.programmer)
  • Re: How to separate interface from implementation when using JARs?
    ... In Java I can use the interface concept. ... int MyAdd; ... I would use this class as an import in my client code: ...
    (comp.lang.java.programmer)