Java Reference
In-Depth Information
F
IGURE
31.10
The client sends the student information in an object to the server.
L
ISTING
31.5
StudentAddress.java
1
public class
StudentAddress
implements
java.io.Serializable {
2
serialized
private
String name;
3
private
String street;
4
private
String city;
5
private
String state;
6
private
String zip;
7
8
public
StudentAddress(String name, String street, String city,
9 String state, String zip) {
10
this
.name = name;
11
this
.street = street;
12
this
.city = city;
13
this
.state = state;
14
this
.zip = zip;
15 }
16
17
public
String getName() {
18
return
name;
19 }
20
21
public
String getStreet() {
22
return
street;
23 }
24
25
public
String getCity() {
26
return
city;
27 }
28
29
public
String getState() {
30
return
state;
31 }
32
33
public
String getZip() {
34
return
zip;
35 }
36 }
The client sends a
StudentAddress
object through an
ObjectOutputStream
on
the output stream socket, and the server receives the
Student
object through the
ObjectInputStream
on the input stream socket, as shown in FigureĀ 31.11. The client uses
the
writeObject
method in the
ObjectOutputStream
class to send data about a stu-
dent to the server, and the server receives the student's information using the
readObject
method in the
ObjectInputStream
class. The server and client programs are given in
Listings 31.6 and 31.7.
Search WWH ::
Custom Search