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