Tomcat以及UDP

一、Tomcat

服务端

  • 自定义 S

  • Tomcat服务器 S :Java后台开发

客户端

  • 自定义 C

  • 浏览器 B

认识一些常用的目录:

  • bin:存放开始和结束的程序

  • conf:配置文件

  • lib:组成包

  • logs:输出日志

  • webapps:网页内容


二、UDP

发短信:不用连接,需要知道对方的地址

复制代码
//还是要等待客户端的连接
public class UdpServerDemo01 {
    public static void main(String[] args) throws Exception {
        //开放端口
        DatagramSocket socket = new DatagramSocket(9090);
        //接收数据包
        byte[] bytes = new byte[1024];
        DatagramPacket packet = new DatagramPacket(bytes, 0, bytes.length);//接收
​
       socket.receive(packet);
​
        System.out.println(packet.getAddress().getHostAddress());
        System.out.println(new String(packet.getData(),0,packet.getLength()));
​
​
​
       //关闭连接
        socket.close();
    }
}
复制代码
//不需要连接服务器
public class UdpClientDemo01 {
    public static void main(String[] args) throws Exception {
        //1.建立一个Socket
        DatagramSocket socket = new DatagramSocket();
        //2.建个包
        String msg ="你好啊服务器";
        //发送给谁
        InetAddress localhost = InetAddress.getByName("localhost");
        int port = 9090;
        //数据,数据的长度起始,要发送给谁
        DatagramPacket packet = new DatagramPacket(msg.getBytes(), 0, msg.getBytes().length, localhost, port);
        //3.发送包
        socket.send(packet);
        //4.关闭流
        socket.close();
    }
}

三、URL

百度一下,你就知道

统一资源定位符:定位资源的,定位互联网上的某一个资源

DNS域名解析 <www.baidu.com> xxx.x..x..x

复制代码
协议://ip地址: 端口/项目名/目录
​
​
public class URLDemo01 {
    public static void main(String[] args) throws MalformedURLException {
        URL url = new URL("http://localhost:8080/helloworld/index.jsp?username=kuangshen&password=123");
​
        System.out.println(url.getProtocol());//协议
        System.out.println(url.getHost());//主机ip
        System.out.println(url.getPort());//端口
        System.out.println(url.getPath());//全路径
        System.out.println(url.getFile());//文件
        System.out.println(url.getQuery());//参数
        try {
            HttpsURLConnection urlConnection = (HttpsURLConnection) url.openConnection();
            InputStream inputStream = urlConnection.getInputStream();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
​
    }
}
相关推荐
她的男孩2 分钟前
同一个接口,为什么销售只看到自己的订单?我拆了 681 行数据权限拦截器的源码
java·后端·架构
卓怡学长9 分钟前
w157基于springboot北部湾地区助农平台
java·spring boot·spring·maven·intellij-idea
小白羊丨11 分钟前
问数 Agent 整体架构、意图识别、历史上下文与 NL2SQL
java·面试·架构
呆呆敲代码的小Y16 分钟前
TCP / UDP 对比介绍
网络·网络协议·tcp/ip·udp·tcp·tcp/udp
Linux-lucky19 分钟前
33-Linux学习之旅之MySQL用户管理
java·linux·运维·学习·mysql·ubuntu
SimonKing24 分钟前
将cURL 命令直接变成 Java 代码?用JQuick-Curl搞起来
java·后端·程序员
凤山老林33 分钟前
企业级文件服务中台:Spring Boot 集成 MinIO 实现分片存储、生命周期管理与多租户隔离
java·spring boot·后端·minio·文件服务
青山木34 分钟前
Hot 100 --- 买卖股票的最佳时机
java·数据结构·算法·leetcode·贪心算法
程序员良辰36 分钟前
Eclipse Memory Analyzer(MAT)入门教程:从生成 Heap Dump 到定位 Java 内存问题
java·ide·eclipse·tomcat·idea
深圳市益普科技有限公司37 分钟前
半导体MES的数字孪生:虚拟调试如何把上线风险提前清零
java·开发语言