import java.net.*; import java.io.*; public class Example1 { public static void main(String[] args) { try { // Connect to a remote server Socket socket = new Socket("www.example.com", 80); // Shut down the input stream of the socket socket.shutdownInput(); } catch (IOException e) { System.out.println("Error: " + e.getMessage()); } } }
import java.net.*; import java.io.*; public class Example2 { public static void main(String[] args) { try { // Listen for incoming connections ServerSocket serverSocket = new ServerSocket(9090); // Accept a connection from a client Socket clientSocket = serverSocket.accept(); // Shut down the input stream of the client socket clientSocket.shutdownInput(); } catch (IOException e) { System.out.println("Error: " + e.getMessage()); } } }Both examples are part of the java.net package library.