目录
1. IP
127.0.0.1 :本机localhost
分类:
公网/私网
私网:192.158.xxx.
ipv4/ipv6:
ipv4:127.0.0.1 4个字节,0~255,
ipv6:128位,8个无符号整数
import java.net.InetAddress;
public class TestInetAddress {
public static void main(String[] args) throws Exception{
InetAddress inetAddress= InetAddress.getByName("127.0.0.1");
System.out.println(inetAddress);
//查询网站ip
InetAddress inetAddress2 = InetAddress.getByName("www.baidu.com");
System.out.println(inetAddress2);
//常用方法
System.out.println(inetAddress2.getAddress());
System.out.println(inetAddress2.getCanonicalHostName());
System.out.println(inetAddress2.getHostName());
}
}
2.端口
进口号用来区分软件的
公有端口:0~1023
HTTP:80
HTTPS:443
FTP:21
Telent:23
程序注册端口:1024~49151
tomcat:8080
MySQL:3306
Oracle:1521
动态、私有 49152~65535
netstat -ano 查看所有端口状态
netstat -ano | findstr "5900" 查看具体端口状态
tasklist|findstr "8696" 查看指定端口的进程
3.通信协议
tcp:用户传输协议
连接,稳定
三次握手,四次挥手
客户端和服务端
udp:用户数据报协议
客户端和服务端没有明确界限
不连接,不稳定
4. tcp文件传输
package TCP;
import java.io.File;
import java.io.FileInputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
public class TCP_server {
public static void main(String[] args)throws Exception {
//客户端
Socket socket = new Socket(InetAddress.getByName("127.0.0.1"),3434);
OutputStream os = socket.getOutputStream();
FileInputStream fis = new FileInputStream("C:/Users/Administrator/Desktop/kail_ack.txt");
byte[] buffer = new byte[1024];
int len;
while((len=fis.read(buffer))!=-1){
os.write(buffer,0,len);
}
fis.close();
os.close();
socket.close();
}
}
package TCP;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
//服务端
public class TCP_socketserver {
public static void main(String[] args) throws Exception {
ServerSocket serverSocket =new ServerSocket(3434);
Socket socket = serverSocket.accept();
InputStream is = socket.getInputStream();
FileOutputStream fos = new FileOutputStream("C:\\Users\\Administrator\\Desktop\\gao.txt");
byte[] buffer = new byte[1024];
int len;
while((len=is.read(buffer))!=-1){
fos.write(buffer,0,len);
}
fos.close();
is.close();
socket.close();
serverSocket.close();
}
}
5.UDP聊天
6.URL
统一资源定位符:定位物联网上某一个资源