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);
        }
​
    }
}
相关推荐
孞㐑¥3 小时前
Linux之Socket 编程 UDP
linux·服务器·c++·经验分享·笔记·网络协议·udp
ladymorgana5 小时前
【Spring boot】tomcat Jetty Undertow对比,以及应用场景
spring boot·tomcat·jetty
Fireworkitte5 小时前
Apache POI 详解 - Java 操作 Excel/Word/PPT
java·apache·excel
weixin-a153003083165 小时前
【playwright篇】教程(十七)[html元素知识]
java·前端·html
DCTANT6 小时前
【原创】国产化适配-全量迁移MySQL数据到OpenGauss数据库
java·数据库·spring boot·mysql·opengauss
2501_915921436 小时前
iOS IPA 混淆实测分析:从逆向视角验证加固效果与防护流程
websocket·网络协议·tcp/ip·http·网络安全·https·udp
2501_915918416 小时前
打造可观测的 iOS CICD 流程:调试、追踪与质量保障全记录
websocket·网络协议·tcp/ip·http·网络安全·https·udp
Touper.6 小时前
SpringBoot -- 自动配置原理
java·spring boot·后端
黄雪超6 小时前
JVM——函数式语法糖:如何使用Function、Stream来编写函数式程序?
java·开发语言·jvm
ThetaarSofVenice6 小时前
对象的finalization机制Test
java·开发语言·jvm