zoukankan      html  css  js  c++  java
  • 客户端出现close_wait

    服务端主动关闭 :
    You have new mail in /var/spool/mail/root
    node1:/root/test#netstat -na | grep 8080
    tcp        0      0 192.168.137.2:8080          192.168.137.3:43433         FIN_WAIT2  
    
    
    客户端没有关闭,此时close_wait
    
    node2:/tmp/newcx#netstat -na | grep 8080
    tcp       14      0 192.168.137.3:43433         192.168.137.2:8080          CLOSE_WAIT  
    You have mail in /var/spool/mail/root
    
    node2:/root/test#cat t18.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.send('4444')
    time.sleep(30)
    s.send('5555')
    s.send('5555')
    
    
    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 
             conn.send('response:'+msg)
             conn.close()
            except Exception,err:
              print err
            #conn.send(msg.upper())#服务端发送消息
        conn.close()#关闭链接
    s.close()#关闭套接字
    
  • 相关阅读:
    要想成为前端大神,那些你不得不知晓的web前端命名规范。
    正确开启Mockjs的三种姿势:入门参考(一)
    1024码农节-向自己致敬!
    ES6 常用总结(前端开发js技术进阶提升总结)
    JS快速构建数组方法
    React绑定事件动态化的实现方法
    JQ遇到$(‘.xxx’).attr(‘display’)一直返回undefined
    你所要掌握的最简单基础的React渲染优化
    MyBatis Generator
    Spring boot集成redis初体验
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348484.html
Copyright © 2011-2022 走看看