Re: Repeated read From Socket is Truncated
- From: Lothar Kimmeringer <news200601@xxxxxxxxxxxxxx>
- Date: Thu, 2 Feb 2006 19:46:23 +0100
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!
.
- Follow-Ups:
- Re: Repeated read From Socket is Truncated
- From: Trouble@Mill
- Re: Repeated read From Socket is Truncated
- References:
- Repeated read From Socket is Truncated
- From: Trouble@Mill
- Re: Repeated read From Socket is Truncated
- From: Gordon Beaton
- Re: Repeated read From Socket is Truncated
- From: Trouble@Mill
- Re: Repeated read From Socket is Truncated
- From: Gordon Beaton
- Re: Repeated read From Socket is Truncated
- From: Trouble@Mill
- Re: Repeated read From Socket is Truncated
- From: Gordon Beaton
- Re: Repeated read From Socket is Truncated
- From: Trouble@Mill
- Repeated read From Socket is Truncated
- Prev by Date: Re: make not needed
- Next by Date: Need to create custom taglib similar to bean:message
- Previous by thread: Re: Repeated read From Socket is Truncated
- Next by thread: Re: Repeated read From Socket is Truncated
- Index(es):
Relevant Pages
|