November 2006
Intermediate to advanced
224 pages
3h 29m
English
Socket clientSock = serverSocket.accept(); ObjectOutputStream os = new ObjectOutputStream( clientSock.getOutputStream( )); // return an object os.writeObject(new Date()); os.close(); |
In this phrase, we return a serialized object to a client. We get a Socket instance returned from the accept() method of the ServerSocket after making a connection with a client. We then create an ObjectOutputStream instance, passing the output stream obtained from the client socket. An ObjectOutputStream is used to write primitive datatypes and graphs of Java objects to an OutputStream. In this example, we write a Date object to the output stream and then close the stream.
The writeObject() method causes the object passed as a parameter to be ...
Read now
Unlock full access