端口,InetSocketAddress类的使用

端口

端口表示计算机上的一个程序的进程:

  • 不同的进程有不同的端口号!用来区分软件
  • 被规定:0~65535
  • TCP,UDP:65535*2 单个协议下,端口号不能冲突
  • 端口分类:
    • 公有端口:0~1023
      • HTTP:80
      • HTTPS:443
      • FTP:21
      • Telent:23
    • 程序注册端口:1024~49151,分配用户或者程序
      • Tomcat:8080
      • MySQL:3306
      • Oracle:1521
    • 动态,私有:49152~65535

常用的与端口相关的DOS命令

netstat -ano   查看所有端口号
netstat -ano|findstr "6728"  查看指定端口号
tasklist|findstr "6728"  查看指定端口号进程
Ctrl+Shift+ESC    快捷键打开任务管理器

测试InetSocketAddress:

package net.study;

import java.net.InetSocketAddress;

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());  // 端口
    }
}

posted @ 2021-07-27 16:55  CH0701  阅读(586)  评论(0)    收藏  举报