Java Reference
In-Depth Information
was able to make use of the hint in the set method by a call to the get method after the output
operation. The Socket methods used for setting and getting this option are as follows:
public int getSendBufferSize () throws SocketException
public void setSendBufferSize (int size) throws SocketException
The send buffer size value determines how many packets will be sent before waiting
for an acknowledgment that the packets have been received at the other application. On a
reliable network, you can set this to a high value to get the best throughput of data. In a worst-
case scenario, you could set the send buffer to the same size as the packet size. In this case,
for every packet sent, an acknowledgment would have to be received—if you needed to send
100 packets, you would need to receive 100 packets. Contrast this with a send buffer that is 100
times larger than the packet size—when sending the 100 packets you would have to receive
only one packet; it would complete in nearly half the time.
Using SO_RCVBUF
This option is similar to SO_SNDBUF , which is used for setting the send buffers. The difference
here is that this option deals with the receive buffers. As with the send buffer option, setting
the receive buffer size value is actually a hint to the platform. To verify the size the buffer was
set to, use the getReceiveBufferSize method. To improve the performance of a high-volume
socket connection, increase the size of the receive buffer. Decreasing this value can reduce
incoming backlog.
public void setReceiveBufferSize (int size) throws SocketException
public int getReceiveBufferSize () throws SocketException
Using SO_BINDADDR
This option indicates the local address that a socket is bound to. This option is read-only. A
socket address cannot be changed after it is created and must be specified in the constructor.
The method signature is as follows:
public InetAddress getLocalAddress ()
One of the possible uses for this method is determining what IP address you are bound to
when running on a computer with multiple IP addresses (e.g., a server with multiple network
cards, a PC with both a local IP address and a networked address, or a computer with both a
network address and a virtual private network address).
The DvdSocketClient
There are a few important points to note about the DVDSocketClient . The socket implementa-
tion in our sample project uses port 3000 by default. Also by default, we use localhost as the
hostname. This is useful when we want to run our application in networking mode on one
machine (i.e., when we do not have access to a network). If we run our application on different
machines, we will have to specify the IP address of the machine that is running the socket
server.
Search WWH ::




Custom Search