两个字节,16位,0~65535
tcp协议下有65535个,udp协议下也有65535个
注意:
1、端口是用来区分软件的
2、端口有两个字节构成:0-65535
3、端口分为tcp和udp两种协议的端口,同一种协议下不能重复
4、定义端口尽量往大的定义,如8888
常用端口:
80:http协议
8080:tomcat服务器
1521:oracle
3306:MySQL
查看所有端口:
netstat -ano
查看指定端口:
netstat -ano|findstr “1120”
查看指定进程:
tasklist|findstr “1120”
Java中使用端口:InetSocketAddress
1、构造器:
new InetSocketAddress(地址|域名,端口)
2、方法:
getAddress();
getPort();
getHostName();
public static void main(String[] args) throws UnknownHostException {
InetSocketAddress socketAddress1 = new InetSocketAddress("127.0.0.1",8080);
InetSocketAddress socketAddress2 = new InetSocketAddress("localhost",9090);
System.out.println(socketAddress1.getHostName());
System.out.println(socketAddress1.getAddress());
System.out.println(socketAddress1.getPort());
System.out.println("------------------");
System.out.println(socketAddress2.getHostName());
System.out.println(socketAddress2.getAddress());
System.out.println(socketAddress2.getPort());
}