Reading and Writing to a Socket

It's unusual to only read from a socket. It's even more unusual to only write to a socket. Most protocols require the client to both read and write.

Some protocols require the reads and the writes to be interlaced. That is:

write
read
write
read
write
read

Other protocols, such as HTTP 1.0, have multiple writes, followed by multiple reads, like this:

write
write
write
read
read
read
read

Other protocols don't care and allow client requests and server responses to be freely intermixed.

Java places no restrictions on reading and writing to sockets. One thread can read from a socket while another thread writes to the socket at the same time. (How does this differ from one thread reading a file while another thread writes to the file?)


Previous | Next | Top | Cafe au Lait

Copyright 1997 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified April 17, 1997