JAVA TCP/IP Socket Implementation (4)
Client Actions
|
Close the socket
|
- Instantiate a Socket object
- Communicate with server
- Send data/requests
- Receive data/replys
- Close the socket
|
- Close the socket when finished communicating
- Both client and server must close their sockets to completely tear
down the connection
- Server must also close down the ServerSocket when no more client connections
are expected
|
try {
sock.close();
}
catch(IOException ioe) {
System.out.println("Close error: " + ioe.getMessage());
}
// Again, close() needs to be called on both sides of the connection, and the server should
// also be sure to close() the ServerSocket when it no longer wishes to accept client
// connections.