Java Reference
In-Depth Information
Figure 17.6 Output of the PurchaseDemo program, which sends a single CustomerOrder
object to the OrderHandler program over a secure socket.
The following code from the PurchaseDemo program (available on the Web
site) simulates an order being sent to the OrderHandler application. Study the
code and try to determine the output of both the PurchaseDemo program and
the OrderHandler program, shown in Figure 17.6 and Figure 17.7, respectively.
SSLSocketFactory factory =
(SSLSocketFactory) SSLSocketFactory.getDefault();
System.out.println(“Creating secure socket to “ + host + “:” + port);
SSLSocket socket = (SSLSocket) factory.createSocket(host, port);
System.out.println(“Enabling all available cipher suites...”);
String [] suites = socket.getSupportedCipherSuites();
socket.setEnabledCipherSuites(suites);
ObjectOutputStream out =
new ObjectOutputStream(socket.getOutputStream());
System.out.println(“Sending order...”);
CustomerOrder order =
new CustomerOrder(1111222233334444L, 1, 2010, 853.79);
out.writeObject(order);
Notice in Figure 17.7 that the OrderHandler waits for an order, processes the
order, and then immediately waits for another one.
Also notice that the client did not start a handshake explicitly using the
startHandshake() method. However, a handshake occurs automatically when
the client attempts to write a CustomerOrder object to the output stream of the
socket.
Figure 17.7 Output of the OrderHandler program, which deserializes the CustomerOrder
object and displays its information.
Search WWH ::




Custom Search