• 7、FIN-WAIT-2


    7、FIN-WAIT-2
    
    处于 FIN-WAIT-1状态的连接收到 ACK 确认包以后进入FIN-WAIT-2状态,这个时候主动关闭方的 FIN 包已经被对方确认,等待被动关闭方发送 FIN 包。
    
    客户端超时关闭,服务端在正在处理,没法关闭,客户端处于FIN-WAIT-2
    
    客户端:
    node2:/root#netstat -an | grep 8080
    tcp        0      0 192.168.137.3:57075         192.168.137.2:8080          FIN_WAIT2  
    
    
    node2:/root/test#cat t19.py 
    import socket
    import time
    import struct
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    # SEND_BUF_SIZE = 2
    s.connect(("192.168.137.2",8080))
    s.settimeout(10)
    s.send('112233')
    s.recv(999)
    
    node2:/root/test#time python t19.py 
    Traceback (most recent call last):
      File "t19.py", line 9, in <module>
        s.recv(999)
    socket.timeout: timed out
    
    real	0m10.066s
    user	0m0.027s
    sys	0m0.021s
    
    
    服务端:
    
    node1:/root#netstat -na | grep 8080
    tcp        0      0 192.168.137.2:8080          0.0.0.0:*                   LISTEN      
    tcp        1      0 192.168.137.2:8080          192.168.137.3:57075         CLOSE_WAIT 
    
    
    node1:/root/test#cat t2.py 
    # coding = utf-8
    # -*- coding:utf-8 -*-
    import socket
    import time
    BUFSIZE=1024
    ip_port = ('192.168.137.2',8080)
    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)#创建套接字
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    
    print("Buffer size [Before]: %d" % s.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF))
    print("Buffer size [Before]: %d" % s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF))
    #s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    print 'alter-----------------------------------------------------------------------';
    print s.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
    print s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
    s.bind(ip_port)#绑定地址
    s.listen(5)#监听链接
    print('server listening8080...')
    while True: #无限等待连接
        conn,addr = s.accept() #接受客户端连接
        print('接到来自%s的链接'%addr[0])
        while True: #通信循环,无限接受客户端信息
            #print conn.getpeername()
            try:
             msg = conn.recv(BUFSIZE) #接受消息的内容
             print 'xxx--------------------xxx'
             print msg
             print 'xxx--------------------xxx'
            except Exception,err:
              break
            if len(msg)==0:break  #如果 不加,已连接的客户端突然断开,recv不再阻塞,发生死循环
            print '111-----------------------111'
            print msg
            print '111-----------------------111'
            try:
             print '开始回复报文' 
             time.sleep(100)
             conn.send('response:'+msg)
            except Exception,err:
              print err
            #conn.send(msg.upper())#服务端发送消息
        conn.close()#关闭链接
    s.close()#关闭套接字
    
  • 相关阅读:
    对比<input type="text" id="">和<asp:TextBox runat="server" ID="">
    EasyUI 启用行内编辑
    水平居中和transform: translateY(-50%) 实现元素垂直居中效果
    表头的一些解释
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">详解
    访问远程桌面 步骤
    jQuery EasyUI API 中文文档
    用JavaScript方式创建easyUI datagrid Column Group(列组)
    jquery中innerheight outerHeight()与height()的区别
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348474.html
Copyright © 2020-2023  润新知