端口
端口
端口概念
端口表示计算机上的一个程序的进程
不同的进程有不同的端口号,用来区分软件
被规定0-65535
TCP/UDP 65535*2 不同协议相同端口不冲突
端口分类:
公有端口: 0-1023
HTTP:80
HTTPS:443
FTP:21
SSH:22
Telent:23
程序注册端口:1024~49151,分配用户或程序
Tomcat:8080
Mysql:3306
Oracal:1512
动态、私有:49152~65535
# 查看端口的dos命令
netstat -ano # 查看所有的端口
netstat -ano|findstr "8080" #查看指定端口的进程
# 任务管理器快捷键 Ctrl +Shift +Esc
端口类:InetSocketAddress
package com.example.network;
import java.net.InetSocketAddress;
public class TestPort {
public static void main(String[] args) {
InetSocketAddress inetSocketAddress = InetSocketAddress.createUnresolved("127.0.0.1", 1234);
InetSocketAddress inetSocketAddress1 = InetSocketAddress.createUnresolved("localhost", 1234);
System.out.println(inetSocketAddress); // 127.0.0.1:1234
System.out.println(inetSocketAddress1); // localhost:1234
System.out.println(inetSocketAddress.getAddress()); // null
System.out.println(inetSocketAddress.getHostName()); // 127.0.0.1
System.out.println(inetSocketAddress.getPort()); // 1234
InetSocketAddress inetSocketAddress2 = InetSocketAddress.createUnresolved("www.baidu.com", 443);
System.out.println(inetSocketAddress2); // www.baidu.com:443
System.out.println(inetSocketAddress2); // www.baidu.com:443
System.out.println(inetSocketAddress2.getAddress()); // null
System.out.println(inetSocketAddress2.getHostName()); // www.baidu.com
System.out.println(inetSocketAddress2.getPort()); // 443
}
}