JAVA网络编程2-端口Port
端口
端口表示计算机上的一个程序的进程
- 不同的进程有不同的端口号,用来区分软件
- 被规定0-65535
- TCP/UDP端口:65535&2 TCP:80,UDP:80,单个协议下端口号不能冲突
- 端口分类:
- 公有端口0-1023
- HTTP:80
- HTTPS:443
- FTP:21
- SSH:22
- TELNET:23
- 程序注册端口:1024-49151,分配给用户或者程序
- Tomcat:8080
- MySQL:3306
- Oracle:1521
- 动态,私有端口:49152-65535
netstat -ano #查看所有的端口
netstat -ano|findstr “5900” #查看指定的端口
tasklist|findstr “8696” #
package com.lessson01;
import java.net.InetSocketAddress;
public class TestInetSocketAddress {
public static void main(String[] args) {
InetSocketAddress socketAddress = new InetSocketAddress("127.0.0.1",8080);
InetSocketAddress socketAddress2 = new InetSocketAddress("localhost",8080);
System.out.println(socketAddress);
System.out.println(socketAddress2);
System.out.println(socketAddress.getAddress());
System.out.println(socketAddress.getHostName());
System.out.println(socketAddress.getPort());
}
}