November 2006
Intermediate to advanced
224 pages
3h 29m
English
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); out.writeObject(myObject); |
Java enables object instances to be serialized and written either to a file or across a network. In this phrase, we show how you can write a serialized object to a network socket. This phrase assumes that we’ve previously created a socket to the server with which we want to communicate. See the phrase “Contacting a Server” in this chapter for more details on creating the socket instance.
In this phrase, we call the getOutputStream() method of the socket instance to get a reference to the socket’s output stream. Using this, we can instantiate an ObjectOutputStream instance. The ObjectOutputStream class is used to serialize ...
Read now
Unlock full access