import sys, socket ''' tcp fast open server sample code execute it before enable tfo flag $ echo 3 | sudo tee /proc/sys/net/ipv4/tcp_fastopen ''' PORT = 80 MSG_FASTOPEN = 0x20000000 def client(): # tfo cookie request s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.sendto("hello\n", MSG_FASTOPEN, (sys.argv[1], PORT)) print s.recv(6) s.close() # tfo data s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.sendto("hello\n", MSG_FASTOPEN, (sys.argv[1], PORT)) print s.recv(6) s.close() def main(): client() if __name__ == '__main__': main()