- Forward


Object Transport
An Introduction with Examples in Java


Prof. David Bernstein
James Madison University

Computer Science Department
bernstdh@jmu.edu

Print

A Reminder
Back SMYC Forward
  • Serialization Defined:
    • The process of creating a "frozen" representation of a "live" (i.e., in-memory) object
  • Uses:
    • Copy objects
    • Provide persistence
    • Transport objects over a communications channel
An Example
Back SMYC Forward

A Simple Class

javaexamples/serialization/Course.java
 
An Example (cont.)
Back SMYC Forward

A More Complicated Class

javaexamples/serialization/CourseDatabase.java
 
The Obvious Approach to Object Transport
Back SMYC Forward
  • Recall:
    • The ObjectOutputStream and ObjectInputStream classes are used to serialize and deserialize objects
    • TCP is stream-oriented
  • Using this for Object Transport:
    • Get a stream from a Socket
    • Decorate it appropriately
An Example Using TCP
Back SMYC Forward

A Server

javaexamples/serialization/CourseDatabaseServer.java
 
An Example Using TCP (cont.)
Back SMYC Forward

A Client

javaexamples/serialization/CourseDatabaseClient.java
 
Using UDP for Object Transport
Back SMYC Forward
  • Recall:
    • UDP is packet-oriented
    • ByteArrayOutputStream and ByteArrayInputStream can be used to create a stream from an array of bytes
  • Using this for Object Transport:
    • Process the byte array in a DatagramPacket as a stream
An Example Using UDP
Back SMYC Forward

A Receiver

javaexamples/serialization/CourseDatabaseReceiver.java
 
An Example Using TCP (cont.)
Back SMYC Forward

A Sender

javaexamples/serialization/CourseDatabaseSender.java
 
There's Always More to Learn
Back -