29.7. Creating Custom Dialogs

 
[Page 856 ( continued )]

Chapter Summary

  • Java supports stream sockets and datagram sockets. Stream sockets use TCP (Transmission Control Protocol) for data transmission, whereas datagram sockets use UDP (User Datagram Protocol). Since TCP can detect lost transmissions and resubmit them, transmissions are lossless and reliable. UDP, in contrast, cannot guarantee lossless transmission.

  • To create a server, you must first obtain a server socket, using new ServerSocket-(port) . After a server socket is created, the server can start to listen for connections, using the accept() method on the server socket. The client requests a connection to a server by using new socket(serverName, port) to create a client socket.

  • Stream socket communication is very much like input/output stream communication after the connection between a server and a client is established. You can obtain an input stream using the getInputStream() method and an output stream using the getOutputStream() method on the socket.

  • A server must often work with multiple clients at the same time. You can use threads to handle the server's multiple clients simultaneously by creating a thread for each connection.

  • Applets are good for deploying multiple clients. They can be run anywhere with a single copy of the program. However, because of security restrictions, an applet client can only connect to the server where the applet is loaded.

  • Java programs can retrieve data from a file on a remote host through a Web server. To do so, first create a URL object using new URL(urlString) , then use openStream() to get an InputStream to read the data from the file.

  • Swing provides a GUI component named javax.swing.JEditorPane that can be used to display text, HTML, and RTF files automatically without writing the code to read data from the file explicitly.

  • Clients and servers that communicate via a datagram socket do not have a dedicated point-to-point channel. Data is transmitted using packets. Datagram sockets use UDP (User Datagram Protocol), which cannot guarantee that the packets are not lost, or not received in duplicate, or received in the order in which they were sent. A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed .

 


Introduction to Java Programming-Comprehensive Version
Introduction to Java Programming-Comprehensive Version (6th Edition)
ISBN: B000ONFLUM
EAN: N/A
Year: 2004
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net