Created
December 8, 2013 09:09
-
-
Save Jxck/7854971 to your computer and use it in GitHub Desktop.
Revisions
-
Jxck created this gist
Dec 8, 2013 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ 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() This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,32 @@ import 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 TCP_FASTOPEN = 23 def server(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.setsockopt(socket.SOL_TCP, TCP_FASTOPEN, 5) s.bind(("", PORT)) s.listen(1024) while True: conn, addr = s.accept() msg = conn.recv(6) print msg conn.send(msg) conn.close() s.close() def main(): server() if __name__ == '__main__': main()