端口有0-65535
tcp和udp所占端口可以相同,各走一套
公用端口:0-1023 别用
-
http 80
-
https 443
-
ftp 21
-
Telent 23
程序注册端口:1024-49151
-
Tomcat 8080
-
MySQL 3306
-
Oracle 1521
-
cmd中查看所有进程
netstat -ano
-
cmd中查看某个端口号所占的进程
netstat -ano|findstr"端口号"
-
cmd中查看某个端口号所占的事务
tasklist|findstr "端口号"
import java.net.InetSocketAddress;
public class TestPort {
public static void main(String[] args) {
InetSocketAddress socketAddress =new InetSocketAddress("localhost",8080);
System.out.println(socketAddress);//localhost/本机ip地址:8080
System.out.println(socketAddress.getAddress());//localhost/本机ip地址
System.out.println(socketAddress.getHostName());//localhost
System.out.println(socketAddress.getHostString());//localhost
System.out.println(socketAddress.getPort());//8080
}
}
浙公网安备 33010602011771号