Skip to content

Instantly share code, notes, and snippets.

@Jxck
Created December 8, 2013 09:09
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jxck/7854971 to your computer and use it in GitHub Desktop.
Save Jxck/7854971 to your computer and use it in GitHub Desktop.
TCP Fast Open – Webを速くするためにGoogleがやっていること Make the Web Faster 4 - Python サンプルコード
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()
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment