zoukankan      html  css  js  c++  java
  • 网络基础知识(一)wireshark 三次握手实践

    wireshark 三次握手简介

    192.168.18.120 IP地址为我的本机虚拟机IP地址

    过滤设置:ip.addr == 192.168.18.120 (ip.addr == 192.168.18.120 显示所有目标或源地址是192.168.18.120的数据包)

    第一次握手

    第二次握手 

    第三次握手 

    观察其中红色方框内的3条数据包就是一次TCP建立连接的过程

    [1]客户端首先向服务器发一个数据包syn位置1,5774->80,嘿,哥们儿,您我想访问你的web资源,能不能把你的80端口打开, 【73--->120】

    [2]服务器向客户端返回一个数据包syn位置1,ack位置1,80->5774,可以啊,我已经把80端口打开了,但是为了保证待会儿可靠传输,你也把你的5774端口打开呗,【120--->73】

    [3]最后,客户端会再向服务器端发送一个数据包ack位置1,5774->80,没问题我也把的5774端口打开了,好的到此一次TCP连接就此建立,【73--->120】

     开始测试,以下为抓取的数据包

    请求数据分析

    服务器响应结果分析

    以上这个什么啥意思?

     响应结果我们可以清楚的看到,服务器响应数据中返回的Openresty 输出的信息ngx.say() 函数执行的结果,这也是我们想要的结果

    ngx.say("Tinywan redis_test_short set result: ", ok)
    ngx.say("redis_test_short result: ", res)

    最后整体抓包

    长链接测试

     

    短连接测试代码

        #  test_redis_long
        location /test_redis_short {
            default_type 'text/html';
            content_by_lua_file "/mnt/hgfs/Linux-Share/Lua/lua_project_v0.01/application/redis/test_short.lua";
        }
    test_short.lua
    --[[-----------------------------------------------------------------------
    * |  Copyright (C) Shaobo Wan (Tinywan)
    * |  Github: https://github.com/Tinywan
    * |  Author: Tinywan
    * |  Date: 2017/5/8 16:25
    * |  Mail: Overcome.wan@Gmail.com
    * |------------------------------------------------------------------------
    * |  version: 1.0
    * |  description: redis 短连接测试
    * |------------------------------------------------------------------------
    --]]
    local redis = require "resty.redis"
    local red = redis:new()
    
    local ok, err = red:connect("127.0.0.1", 63700)
    if not ok then
        ngx.say("failed to connect: ", err)
        return
    end
    
    local res, err = red:auth("tinywan123456")
    if not res then
        ngx.say("failed to authenticate: ", err)
        return
    end
    
    ok, err = red:set("redis_test_short", "redis_test_short"..ngx.time())
    if not ok then
        ngx.say("failed to set dog: ", err)
        return
    end
    
    ngx.say("Tinywan redis_test_short set result: ", ok)
    
    local res, err = red:get("redis_test_short")
    if not res then
        ngx.say("failed to get dog: ", err)
        return
    end
    
    if res == ngx.null then
        ngx.say("dog not found.")
        return
    end
    
    ngx.say("redis_test_short result: ", res)
  • 相关阅读:
    CSS 中 nth-child 和 nth-of-type 的区别
    Git HTTPS 方式自动保存用户名密码
    nginx 配置代理某个路径
    VS Code 常用插件列表
    安装node-sass的正确姿势【转】
    MongoDB 3.4.2 配置 CentOS 6.5 远程连接
    CentOS 6.5 升级 PHP 到5.6
    常用正则表达式整理[JavaScript]
    nginx提示413 Request Entity Too Large解决方法
    Linux远程执行Shell命令或脚本
  • 原文地址:https://www.cnblogs.com/tinywan/p/6840573.html
Copyright © 2011-2022 走看看