网络编程Port-InetSocketAddress

端口有0-65535

tcp和udp所占端口可以相同,各走一套

公用端口:0-1023 别用

  • http 80

  • https 443

  • ftp 21

  • Telent 23

程序注册端口:1024-49151

  • Tomcat 8080

  • MySQL 3306

  • Oracle 1521


  1. cmd中查看所有进程

    netstat -ano

  2. cmd中查看某个端口号所占的进程

    netstat -ano|findstr"端口号"

  3. 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
  }
}

 

posted on 2021-03-09 11:53  要给小八赚罐头钱  阅读(55)  评论(0)    收藏  举报