November 2006
Intermediate to advanced
224 pages
3h 29m
English
Socket clientSock = serverSocket.accept(); DataOutputStream out = new DataOutputStream( clientSock.getOutputStream()); out.writeInt(someValue); out.close(); |
This phrase shows an example of how to return a response from a server to a client. The accept() method of the ServerSocket instance will return a Socket instance when a connection is made with a client. We then get the socket’s output stream by calling the getOutputStream() method of the socket. We use the output stream to instantiate a DataOutputStream, which we then call the writeInt() method on to write an integer value, sending binary data to the client. Finally, we close the socket using the close() method of the Socket.
In this phrase, we use the write() method, ...