端口Port了解
端口表示计算机上的一个程序的进程
- 不同的进程有不同的端口号,用来区分软件
- 被规定0~65535
- 单个协议下,端口号不能冲突
- 端口分类
-
公有端口0~1023
- http:80
- https:43
- ftp:21
- telent:23
-
程序注册端口:1024~49151,分配用户或者程序
- Tomcat:8080
- MySQL:3306
- Oracle:1521
-
动态、私有:49152~65535
-
# 查看所有的端口
netstat -ano
# 查看指定的端口
netstat -ano|findstr "端口号"
# 查看指定端口是哪一个进程
tasklist|findstr "端口号"
# 打开任务管理器的快捷键
ctrl+shift+Esc
测试InetSocketAddress类的Java代码:
import java.net.InetSocketAddress;
/**
* 测试InetSocketAddress类
*
* @author 87682
*/
public class TestInetSocketAddress {
public static void main(String[] args) {
InetSocketAddress inetSocketAddress = new InetSocketAddress("127.0.0.1", 8080);
InetSocketAddress inetSocketAddress2 = new InetSocketAddress("localhost", 8080);
System.out.println(inetSocketAddress);
System.out.println(inetSocketAddress2);
//获取地址和端口
System.out.println(inetSocketAddress.getAddress());
System.out.println(inetSocketAddress.getHostName());
System.out.println(inetSocketAddress.getPort());
}
}