zoukankan      html  css  js  c++  java
  • tcp windows限流

    客户端:
    import socket
    import time
    s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    SEND_BUF_SIZE = 131
    RECV_BUF_SIZE = 3
    s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    s.setsockopt( socket.SOL_SOCKET, socket.SO_SNDBUF, SEND_BUF_SIZE)
    s.setsockopt( socket.SOL_SOCKET, socket.SO_RCVBUF, RECV_BUF_SIZE)
    print s.getsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF)
    print s.getsockopt(socket.SOL_SOCKET, socket.SO_SNDBUF)
    
    s.connect(("192.168.137.2",8080))
    s.settimeout(10)
    #print s.getsockopt()
    print s.getsockname()
    print s.getpeername()
    #s.sendall("this is shutdown test" + "
    ")
    print dir(socket.herror)
    print(socket.SHUT_RDWR)
    print(socket.SHUT_RD)
    print(socket.SHUT_WR)
    #print s.recv(90)
    s.send('1234567890')
    print s.recv(900)
    
    
    
    
    
    C:Python27python.exe C:/Users/TLCB/PycharmProjects/untitled2/http/t5.py
    3
    131
    ('192.168.137.1', 52379)
    ('192.168.137.2', 8080)
    ['__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__getitem__', '__getslice__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__unicode__', '__weakref__', 'args', 'errno', 'filename', 'message', 'strerror']
    2
    0
    1
    Traceback (most recent call last):
      File "C:/Users/TLCB/PycharmProjects/untitled2/http/t5.py", line 25, in <module>
        print s.recv(900)
    socket.timeout: timed out
    
    将RECV_BUF_SIZE 设置为3,接收就堵塞了
    
    node1:/root#tcpdump -S -i eth1 '((tcp) and  (port 8080) and (host 192.168.137.1))'
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on eth1, link-type EN10MB (Ethernet), capture size 65535 bytes
    16:54:55.973701 IP 192.168.137.1.52379 > node1.webcache: Flags [S], seq 2313382742, win 3, options [mss 1460,nop,wscale 2,nop,nop,sackOK], length 0
    16:54:55.973734 IP node1.webcache > 192.168.137.1.52379: Flags [S.], seq 678359211, ack 2313382743, win 1536, options [mss 256,nop,nop,sackOK,nop,wscale 6], length 0
    16:54:55.973855 IP 192.168.137.1.52379 > node1.webcache: Flags [.], ack 678359212, win 0, length 0
    
    
    16:54:55.975541 IP 192.168.137.1.52379 > node1.webcache: Flags [P.], seq 2313382743:2313382753, ack 678359212, win 0, length 10
    16:54:55.975579 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382753, win 24, length 0
    16:54:56.177400 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382753, win 24, length 0
    16:54:56.177570 IP 192.168.137.1.52379 > node1.webcache: Flags [.], ack 678359212, win 0, length 0
    16:54:56.579797 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382753, win 24, length 0
    16:54:56.580001 IP 192.168.137.1.52379 > node1.webcache: Flags [.], ack 678359212, win 0, length 0
    16:54:57.383700 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382753, win 24, length 0
    16:54:57.383843 IP 192.168.137.1.52379 > node1.webcache: Flags [.], ack 678359212, win 0, length 0
    16:54:58.992531 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382753, win 24, length 0
    16:54:58.993114 IP 192.168.137.1.52379 > node1.webcache: Flags [.], ack 678359212, win 0, length 0
    16:55:02.209148 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382753, win 24, length 0
    16:55:02.210820 IP 192.168.137.1.52379 > node1.webcache: Flags [.], ack 678359212, win 0, length 0
    16:55:05.742327 IP node1.webcache > 192.168.137.1.52294: Flags [.], ack 3720633955, win 24, length 0
    16:55:05.742976 IP 192.168.137.1.52294 > node1.webcache: Flags [.], ack 2178877144, win 0, length 0
    16:55:05.970616 IP 192.168.137.1.52379 > node1.webcache: Flags [F.], seq 2313382753, ack 678359212, win 0, length 0
    16:55:06.010859 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382754, win 24, length 0
    16:55:12.403217 IP node1.webcache > 192.168.137.1.52379: Flags [.], ack 2313382754, win 24, length 0
    16:55:12.403930 IP 192.168.137.1.52379 > node1.webcache: Flags [.], ack 678359212, win 0, length 0
    16:55:13.411011 IP node1.webcache > 192.168.137.1.52346: Flags [.], ack 619468276, win 24, length 0
    16:55:13.411560 IP 192.168.137.1.52346 > node1.webcache: Flags [.], ack 1963159324, win 0, length 0
    
    
    但是这个在linux下不生效
  • 相关阅读:
    【Lintcode】112.Remove Duplicates from Sorted List
    【Lintcode】087.Remove Node in Binary Search Tree
    【Lintcode】011.Search Range in Binary Search Tree
    【Lintcode】095.Validate Binary Search Tree
    【Lintcode】069.Binary Tree Level Order Traversal
    【Lintcode】088.Lowest Common Ancestor
    【Lintcode】094.Binary Tree Maximum Path Sum
    【算法总结】二叉树
    库(静态库和动态库)
    从尾到头打印链表
  • 原文地址:https://www.cnblogs.com/hzcya1995/p/13348532.html
Copyright © 2011-2022 走看看