Java Reference
In-Depth Information
Class of Service
As you learned in the previous chapter, different types of Internet services have different
performance needs. For instance, live streaming video of sports needs relatively high
bandwidth. On the other hand, a movie might still need high bandwidth but be able to
tolerate more delay and latency. Email can be passed over low-bandwidth connections
and even held up for several hours without major harm.
Four general traffic classes are defined for TCP:
• Low cost
• High reliability
• Maximum throughput
• Minimum delay
These traffic classes can be requested for a given Socket . For instance, you can request
the minimum delay available at low cost. These measures are all fuzzy and relative, not
guarantees of service. Not all routers and native TCP stacks support these classes.
The setPerformancePreferences() method expresses the relative preferences given
to connection time, latency, and bandwidth for sockets accepted on this server:
public void setPerformancePreferences ( int connectionTime , int latency ,
int bandwidth )
For instance, by setting connectionTime to 2, latency to 1, and bandwidth to 3, you
indicate that maximum bandwidth is the most important characteristic, minimum la‐
tency is the least important, and connection time is in the middle:
ss . setPerformancePreferences ( 2 , 1 , 3 );
Exactly how any given VM implements this is implementation dependent. The under‐
lying socket implementation is not required to respect any of these requests. They only
provide a hint to the TCP stack about the desired policy. Many implementations in‐
cluding Android ignore these values completely.
HTTP Servers
This section shows several different HTTP servers you can build with server sockets,
each with a different special purpose and each slightly more complex than the previous
one.
HTTP is a large protocol. As you saw in Chapter 5 , a full-featured HTTP server must
respond to requests for files, convert URLs into filenames on the local system, respond
to POST and GET requests, handle requests for files that don't exist, interpret MIME types,
and much, much more. However, many HTTP servers don't need all of these features.
Search WWH ::




Custom Search