一、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); } } }
发表评论