| |
19. 9. 5. 套接字信息 |
|
import java.io.IOException;
import java.net.Socket;
import java.net.SocketException;
import java.net.UnknownHostException;
public class MainClass {
public static void main(String[] args) {
try {
Socket theSocket = new Socket("127.0.0.1", 80);
System.out.println("Connected to " + theSocket.getInetAddress() + " on port "
+ theSocket.getPort() + " from port " + theSocket.getLocalPort() + " of "
+ theSocket.getLocalAddress());
} catch (UnknownHostException ex) {
System.err.println(ex);
} catch (SocketException ex) {
System.err.println(ex);
} catch (IOException ex) {
System.err.println(ex);
}
}
}
|
|
|