当前位置: 代码网 > it编程>编程语言>Java > Tomcat以及UDP

Tomcat以及UDP

2024年08月02日 Java 我要评论
服务端自定义 STomcat服务器 S :Java后台开发客户端自定义 C浏览器 B认识一些常用的目录:bin:存放开始和结束的程序conf:配置文件lib:组成包logs:输出日志webapps:网页内容。

一、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);
        }
​
    }
}
(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com