0
点赞
收藏
分享

微信扫一扫

远程通信协议基础

陆佃 2021-09-24 阅读 84
  • 一个http请求


  • 应用层协议:
    http
    ftp
    smtp
    telnet

  • OSI七层网络模型


  • 一个http请求访问网站的数据传输过程

  • 负载均衡
    二层负载->对外提供VIP(虚拟ip),集群中每个机器采用相同ip,不同的Mac地址
    三层负载->对外提供VIP(虚拟ip),集群中每个机器采用不同的ip地址
    四层负载->传输层的负载,包含ip和端口,通过修改ip或者端口来完成负载
    七层负载->应用层负载,根据请求url/http请求报文 来进行负载

TCP/IP协议的可靠性
1.建立连接机制
2.三次握手建立连接



3.SYN攻击
4.连接的关闭:四次挥手



5.TCP是全双工
6.长连接,发送心跳包维持连接
  • JAVA应用中如何建立传输案例
    socket->套接字
public class ServerSocketDemo {

    public static void main(String[] args) {
        ServerSocket serverSocket=null;
        Socket socket=null;
        BufferedReader in=null;
        try {
            //服务器监听一个端口,ip(默认本机)
             serverSocket = new ServerSocket(8080);
            //接收客户端连接(阻塞)
             socket = serverSocket.accept();
            //获取输入流
             in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            //打印接收到信息
            System.out.println(in.readLine());
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                serverSocket.close();
                socket.close();
                in.close();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }
    }

}

public class ClentSocketDemo {
    public static void main(String[] args) {
        Socket socket = null;
        PrintWriter out = null;
        try {
            socket = new Socket("localhost", 8080);
            out = new PrintWriter(socket.getOutputStream(), true);
            out.println("hello,ZZB");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if(socket!=null){
                    socket.close();
                }
                if(out!=null){
                    out.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
举报

相关推荐

0 条评论