Java Reference
In-Depth Information
the other player. If the game is won or a draw, the server sends the status ( PLAYER1_WON ,
PLAYER2_WON , or DRAW ) to both players.
The implementation of Java network programs at the socket level is tightly synchronized.
An operation to send data from one machine requires an operation to receive data from the
other machine. As shown in this example, the server and the client are tightly synchronized
to send or receive data.
33.11
What would happen if the preferred size for a cell is not set in line 227 in Listing
31.10?
Check
Point
33.12
If a player does not have the turn but clicks on an empty cell, what will the client
program in Listing 31.10 do?
K EY T ERMS
client socket 1141
domain name 1140
domain name server
packet-based communication
1140
server socket
1140
1140
socket 1140
stream-based communication
localhost
1141
1140
IP address
1140
TCP
1140
port
1140
UDP
1140
C HAPTER S UMMARY
1.
Java supports stream sockets and datagram sockets. Stream sockets use TCP (Trans-
mission 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.
2.
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.
3.
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.
4.
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.
Q UIZ
Answer the quiz for this chapter online at www.cs.armstrong.edu/liang/intro10e/quiz.html .
 
 
Search WWH ::




Custom Search