Re: non blocking sockets and alternatives
- From: "Matt Humphrey" <matth@xxxxxxxx>
- Date: Fri, 20 Mar 2009 07:59:44 -0400
"EJP" <esmond.not.pitt@xxxxxxxxxxxxxxx> wrote in message
news:MkGwl.29741$cu.3965@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
it seems Java structures the stream
between client and server by doing the following:
size_of_data + the_data
Nope. It just sends the data you sent. Sometimes *applications* prepend a
size word to a transaction, so you know when you've read it all.
A mistake TCP novices frequently make is to think that the data blocks they
write are preserved as blocks to be read. Unfortunately, small byte arrays
on loopback or local LAN will reinforce this illusion. In reality, however,
the stream truly has no boundaries between what is written and what is read.
The network is free to concatenate and break up the stream as it sees fit,
so long as it preserves the underlying byte sequence. The main techniques
for identifying application-specific chunks are:
Send a fixed-length byte count and then the data
Use a particular byte (e.g. 0, \r, \r\n, etc) as a terminator
Use fixed-length messages.
Use one message per connection
When reading, assume the data will arrive in fragments and readFully until
you have it all.
Matt Humphrey http://www.iviz.com/
.
- References:
- non blocking sockets and alternatives
- From: conrad
- Re: non blocking sockets and alternatives
- From: EJP
- non blocking sockets and alternatives
- Prev by Date: Re: Webcam in browser
- Next by Date: Re: JSP login from only a single pc
- Previous by thread: Re: non blocking sockets and alternatives
- Next by thread: The basic standard of real Excel-like reporting tool
- Index(es):
Relevant Pages
|